Segmenting an image according a threshold

1 Ansicht (letzte 30 Tage)
med-sweng
med-sweng am 30 Okt. 2013
Bearbeitet: Ashish Uthama am 31 Okt. 2013
Say that I have a grayscale image, which values range from `[0,255]`. Say that I want the pixels which values are larger than or equal to `66` for instance to be `white`, and the rest pixels to be `black`. How can I do that in `MATLAB`?
Thanks.

Antworten (2)

Image Analyst
Image Analyst am 30 Okt. 2013
Bearbeitet: Image Analyst am 30 Okt. 2013
The easiest way by far, is to simply threshold:
binaryImage = grayImage >= 66;
Ashish's method doesn't create black pixels, and Kevin's is inefficient. My fast and efficient method will create a binary image which is used in virtually all processing afterwards, such as labeling, morphology, regionprops, hole filling, etc.

Kevin Claytor
Kevin Claytor am 30 Okt. 2013
thresh = 66;
I(I < thresh) = 0;
I(I > thresh) = 255;
  1 Kommentar
Ashish Uthama
Ashish Uthama am 30 Okt. 2013
Bearbeitet: Ashish Uthama am 31 Okt. 2013
[Edit, I meant to correct Kevin's code, pointing out the need for >=]
I(I >= thresh) = 255;

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by