0

I have to segment a region from a monochrome image.

After the application of the command 'graythreshold' in my code, the command 'im2bw' requires a threshold value to expand the binary image containing only the ROI, so that I can take the complement of that binary image and subtract and obtain the ROI.

However, the threshold value I select for one image, isn't applicable to the other images specially if the main region of segmentation is much below the level. For some images, the threshold value of 0.13 works while for lower intensity images it can be around 0.03.

How do I code it in such a way that to expand the binary image, the part of the code should automatically analyze the image and set a threshold level rather than me changing it for each image?

mel
  • 9
  • 3

1 Answers1

2

You should use the function graythresh, which uses Otsu's method.

The idea in Otsu's method is to exhaustively try different thresholds and see which one minimizes the variance in each part.

Andrey Rubshtein
  • 20,795
  • 11
  • 69
  • 104
  • I have used graythresh. The image obtained contains a smaller ROI, so to expand that region, it was said that after the graythresh command, 'im2bw' command should be used with a threshold value so that it gives a binary image with a Larger ROI. But one threshold value won't work for other images. – mel Jan 08 '15 at 09:12
  • 1
    @mel If you have "used" `graythresh` then you don't seem to understand how it works. `graythresh` **adaptively** determines the **best** threshold to use. It performs some basic statistics and chooses the threshold that maximizes the inter-class separability assuming that there are only two classes of pixels in your image: foreground / background. Please update your question so we know what you're really after. Therefore, the threshold should change with each image. Did you try doing something like: `B = im2bw(A, graythresh(A));` where `A` is the image? – rayryeng Jan 08 '15 at 15:38