Thresholding and Binarising and doubling

4 views (last 30 days)
Actually, I have very simple doubt. what is the difference between following commands and its output, what is the difference between b,c and d? please explain clearly. I know this is very simple thing. but I was bit confuse in a something in an online course. if we want to threshold a grey scale array, do we need to definetely convert it to binary image and do the thresholding like b?
a=imshow('cameraman.tif'); % a is a 256x256 uint8 greyscale image
b=im2bw(a,155/255); % imbinarize can be used alternatively
c=a>155
d=double(a)

Accepted Answer

Gouri Chennuru
Gouri Chennuru on 25 Sep 2020
Hi Yasasween,
In the statement b,
b=im2bw(a,155/255);
b = im2bw(I,level) im2bw” produces binary images from indexed, intensity, or RGB images. To do this, it converts the input image to grayscale format (if it is not already an intensity image), and then uses thresholding to convert this grayscale image to binary. The output binary image has values of 1 (white) for all pixels in the input image with luminance greater than level and 0 (black) for all other pixels.
im2bw is not recommended. Use imbinarize instead. The default luminance threshold of im2bw is not optimal for most images.
You can use the imbinarize, do the thresolding convert it to a binary image.
In the statement c,
c=a>155
It just returns a logical array with elements set to logical 1 (true) where A is greater than B; otherwise, the element is logical 0 (false). The test compares only the real part of numeric arrays. gt returns logical 0 (false) where A or B have NaN or undefined categorical elements.
In the statement d,
d=double(a)
double converts symbolic values to MATLAB double precision, so here it converts from uint8 to double type.
Hope this Helps!

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!