why I must enclose array bracket '[]' to show the image on next process after apply multithresh?
1 view (last 30 days)
Show older comments
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
Adam
on 21 Oct 2016
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!
Accepted Answer
Guillaume
on 21 Oct 2016
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)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!