MATLAB: Why I must enclose array bracket ‘[]’ to show the image on next process after apply multithresh

arrayImage Acquisition ToolboxImage Processing Toolboximshowmultithresh()otsu

I applied multi threshold using Otsu and show the result of the process using this script. it runs well.
a=imread('segment.jpg');
figure, imshow(a);
b=imadjust(a, [0.8 1],[]);
figure, imshow(b);
level = multithresh(b);
seg_I = imquantize(b,level);
figure, imshow(seg_I, []);
j=imcomplement(seg_I);
figure, imshow(j,[]); title('image complement');
but, why I must enclose array bracket '[]' to show the image on next process after apply multithresh? please help, thanks ^^

Best Answer

The [] is used to override the default 'DisplayRange' used by imshow. If you don't specify a 'DisplayRange', imshow works it out from the class of the image. If the image is double, imshow uses [0 1], if the image is uint8, imshow uses [0 255].
When you load your jpg image, your image a is most likely of class uint8 with intensities in the range [0 255]. the imadjust'ed b is also of class uint8 with intensities in the same range. However, the call to imquantize will create seg_I of type double containing integer values 1 or 2 (since you only have one quantisation level). As said, by default imshow uses [0 1] for a |double image, and since all the intensities are greater than 1, they'll all appear white. Passing [] to imshow tells it to use the minimum and maximum intensities of the image as 'DisplayRange'. If you don't want to do that, in your particular case, you could simply do:
seg_I = imquantize(b,level, [0 1]); %map to output levels [0 1] instead of default [1 2]
imshow(seg_I);
In any case, I'm not sure why you're using imquantize when you have only one quantisation level. You're effectively binarising the image, so imbinarize seems more appropriate:
seg_I = imbinarize(b, level); %creates a logical image with intensity 0 or 1.
imshow(seg_I);