Image Processing Toolbox User's Guide |
Finding Peaks and Valleys
Grayscale images can be thought of in three dimensions: the x- and y-axes represent pixel positions and the z-axis represents the intensity of each pixel. In this interpretation, the intensity values represent elevations, as in a topographical map. The areas of high intensity and low intensity in an image, peaks and valleys in topographical terms, can be important morphological features because they often mark relevant image objects.
For example, in an image of several spherical objects, points of high intensity could represent the tops of the objects. Using morphological processing, these maxima can be used to identify objects in an image.
This section covers these topics:
Terminology
This section uses the following terms.
Understanding the Maxima and Minima Functions
An image can have multiple regional maxima or minima but only a single global maximum or minimum. Determining image peaks or valleys can be used to create marker images that are used in morphological reconstruction.
This figure illustrates the concept in 1-D.
Finding Areas of High or Low Intensity
The toolbox includes functions that you can use to find areas of high or low intensity in an image:
imregionalmax
and imregionalmin
functions identify all regional minima or maxima.
imextendedmax
and imextendedmin
functions identify all regional minima or maxima that are greater than or less than a specified threshold.
The functions accept a grayscale image as input and return a binary image as output. In the output binary image, the regional minima or maxima are set to 1
; all other pixels are set to 0
.
For example, this simple image contains two primary regional maxima, the blocks of pixels containing the value 13
and 18
, and several smaller maxima, set to 11
.
The binary image returned by imregionalmax
pinpoints all these regional maxima.
You might want only to identify areas of the image where the change in intensity is extreme; that is, the difference between the pixel and neighboring pixels is greater than (or less than) a certain threshold. For example, to find only those regional maxima in the sample image, A
, that are at least two units higher than their neighbors, use imextendedmax
.
Suppressing Minima and Maxima
In an image, every small fluctuation in intensity represents a regional minimum or maximum. You might only be interested in significant minima or maxima and not in these smaller minima and maxima caused by background texture.
To remove the less significant minima and maxima but retain the significant minima and maxima, use the imhmax
or imhmin
function. With these functions, you can specify a contrast criteria or threshold level, h, that suppresses all maxima whose height is less than h or whose minima are greater than h.
For example, this simple image contains two primary regional maxima, the blocks of pixels containing the value 14
and 18
, and several smaller maxima, set to 11
.
To eliminate all regional maxima except the two significant maxima, use imhmax
, specifying a threshold value of 2
. Note that imhmax
only affects the maxima; none of the other pixel values are changed. The two significant maxima remain, although their heights are reduced.
This figure takes the second row from the sample image to illustrate in 1-D how imhmax
changes the profile of the image.
Imposing a Minimum
You can emphasize specific minima (dark objects) in an image using the imimposemin
function. The imimposemin
function uses morphological reconstruction to eliminate all minima from the image except the minima you specify.
To illustrate the process of imposing a minimum, this code creates a simple image containing two primary regional minima and several other regional minima.
mask = uint8(10*ones(10,10)); mask(6:8,6:8) = 2; mask(2:4,2:4) = 7; mask(3,3) = 5; mask(2,9) = 9 mask(3,8) = 9 mask(9,2) = 9 mask(8,3) = 9
Creating a Marker Image
To obtain an image that emphasizes the two deepest minima and removes all others, create a marker image that pinpoints the two minima of interest. You can create the marker image by explicitly setting certain pixels to specific values or by using other morphological functions to extract the features you want to emphasize in the mask image.
This example uses imextendedmin
to get a binary image that shows the locations of the two deepest minima.
Applying the Marker Image to the Mask
Now use imimposemin
to create new minima in the mask image at the points specified by the marker image. Note how imimposemin
sets the values of pixels specified by the marker image to the lowest value supported by the datatype (0
for uint8
values). imimposemin
also changes the values of all the other pixels in the image to eliminate the other minima.
I = imimposemin(mask,marker) I = 11 11 11 11 11 11 11 11 11 11 11 8 8 8 11 11 11 11 11 11 11 8 0 8 11 11 11 11 11 11 11 8 8 8 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 0 0 0 11 11 11 11 11 11 11 0 0 0 11 11 11 11 11 11 11 0 0 0 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11
This figure illustrates in 1-D how imimposemin
changes the profile of row 2 of the image.
Flood-Fill Operations | Distance Transform |
© 1994-2005 The MathWorks, Inc.