Image Segmentation 227
2. To bring out hidden detail. This was illustrated with paper and x-ray images. In
both, the detail was obscured because of the similarity of the gray levels involved.
But thresholding can be vital for other purposes:
3. When we want to remove a varying background from an image. An example of
this was the paper clips image shown previously; the paper clips are all light, but
the background in fact varies considerably. Thresholding at an appropriate value
completely removes the background to show just the objects.
9.4 Choosing an Appropriate Threshold Value
We have seen that one of the important uses of thresholding is to isolate objects from
their background. We can then measure the sizes of the objects, or count them. Clearly
the success of these operations depends very much on choosing an appropriate threshold
level. If we choose a value too low, we may decrease the size of some of the objects, or
reduce their number. Conversely, if we choose a value too high, we may begin to include
extraneous background material.
Consider, for example, the image
pinenuts.png, and suppose we try to threshold using
the
im2bw f unction and various threshold values t for 0 < t < 1.
MATLAB/Octave
>> n = imread(’pinenuts.png’);
>> imshow(n);
>> n1 = im2bw(n,0.35);
>> n2 =im2bw(n,0.55);
>> figure,imshow(n1),figure,imshow(n2)
All the images are shown in Figure 9.5. One approach is to investigate the histogram of the
n: Original image n1: Threshold too low n2: Threshold too high
FIGURE 9.5: Attempts at thresholding
image, and see if there is a clear spot to break it up. Sometimes this can work well, but not
always.
Figure 9.6 shows various histograms. In each case, the image consists of objects on a
background. But only for some histograms is it easy to see where we can split it. In both
the blood and daisies images, we could split it up about half way, or at the “valley” between
the peaks, but for the paramecium and pinenut images, it is not so clear, as there would
appear to be three peaks—in each case, one at the extreme right.