why I must enclose array bracket '[]' to show the image on next process after apply multithresh?

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 ^^

3 Comments

Who told you that you do have to? Have you tried doing so without? Usually it is only necessary to pass [] as an argument to a Matlab builtin function if it is an argument you don't want to specify, but you do want to specify a later one. This is quite rare, but min or max is an example where it is often used e.g
a = rand( 10, 10 );
min( a, [], 2 )
to run the min on the 2nd dimension.
Using [] as the final argument seems to be superfluous though because it should be interpreted the same as not including the argument at all as far as I am aware, in a builtin function, that is.
im just follow matlab documentation to apply otsu multithresh on my scipt and got my confusion about it. only white image appeared when im not using the bracket. thanks for your comment :)
Ok, that makes sense, I haven't used it in those circumstances so never read up about the specifics of bypassing that argument. It is an ugly way for Mathworks to solve the problem, but I guess a lack of overloading in Matlab leads to this kind of thing!

Sign in to comment.

 Accepted 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);

More Answers (0)

Categories

Asked:

on 21 Oct 2016

Commented:

on 21 Oct 2016

Community Treasure Hunt

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

Start Hunting!