MATLAB: How to solve this problem

digital image processingImage Processing Toolboximage segmentationMATLAB

Here I attached the warning problem of error. How can I solve this? My source code has been attached here.

Best Answer

You chose a threshold where there were no blobs. Pick a threshold where you actually have some blobs present.
But you can't because, for some reason, you're trying to segment in HSV colorspace when your image is grayscale. Because R = G = B, there are no colors and so the hue and saturation channels are all zero, and since you use that to threshold, your threshold is zero and your image is zero, hence no blobs at all. Just because you have three color channels doesn't mean that the image will have hue or saturation.
Do not segment a gray scale image in any color space such as RGB or HSV. Just call rgb2gray()
grayImage = rgb2gray(rgbImage);
or take any one of the color channels:
grayImage = rgbImage(:, :, 2); % Use the green channel.