5. MORPHOLOGICAL AND OTHER AREA OPERATIONS
5.2 Opening and Closing Operators Opening
which is the definition of Ac⊕B^
The erosion operation also brings up an issue that was not a concern at dilation; the idea of a
"don't care" state in the structuring element. When using a strictly binary structuring element to perform an erosion, the member black pixels must correspond to black pixels in the image in order to set the pixel in the result, but the same is not true for a white (0) pixel in the structuring element. We don't care what the corresponding pixel in the image might be when the structuring element pixel is white.
5.2 Opening and Closing Operators Opening
The application of an erosion immediately followed by a dilation using the same structuring element is refined to as an opening operation. The name opening is a descriptive one, describing the observation that the operation tends to "open" small gaps or spaces between touching objects in an image. This effect is most easily observed when using the simple structuring element. Figure 5.6 shows image having a collection of small objects, some of them touching each other. After an opening using simple the objects are better isolated, and might now counted or classified.
Figure 5.6 The use of opening: (a) An image having many connected objects, (b) Objects can be isolated by opening using the simple structuring element, (c) An image that has been subjected to noise, (d) The noisy image after opening showing that the black noise pixels have been removed.
Figure 5.6 also illustrates another, and quite common, usage of opening: the removal of noise.
When a noisy gray-level image is thresholded some of the noise pixels are above the threshold, and result in isolated pixels in random locations. The erosion step in an opening will remove isolated pixels as well as boundaries of objects, and the dilation step will restore most of the boundary pixels without restoring the noise. This process seems to be successful at removing spurious black pixels, but does not remove the white ones.
Closing
A closing is similar to an opening except that the dilation is performed first, followed by an erosion using the same structuring element. If an opening creates small gaps in the image, a closing will fill them, or "close" the gaps. Figure 5.7 shows a closing applied to the image of
Introduction to Image Processing and Computer Vision by LUONG CHI MAI http://www.netnam.vn/unescocourse/computervision/computer.htm
Figure 5.6d, which you may remember was opened in an attempt to remove noise. The closing removes much of the white pixel noise, giving a fairly clean image.
Figure 5.7 The result of closing Figure 5.6d using the simple structuring element.
Closing can also be used for smoothing the outline of objects in an image. Sometimes digitization followed by thresholding can give a jagged appearance to boundaries; in other cases the objects are naturally rough, and it may be necessary to determine how rough the outline is. In either case, closing can be used. However, more than one structuring element may be needed, since the simple structuring element is only useful for removing or smoothing single pixel irregularities. Another possibility is repeated application of dilation followed by the same number of erosions; N dilation/erosion applications should result in the smoothing of irregularities of N pixels in size.
First consider the smoothing application, and for this purpose Figure 5.7 will be used as an example. This image has been both opened and closed already, and another closing will not have any effect. However, the outline is still jagged, and there are still white holes in the body of the object. An opening of depth 2 (that is two dilations followed by two erosions) gives Figure 5.8a. Note that the holes have been closed, and that most of the outline irregularities are gone. On opening of depth 3 very little change is seen (one outline pixel is deleted), and no figure improvement can be hoped for. The example of the chess piece in the same figure shows more specifically the kind of irregularities introduced sometimes by thresholding, and illustrates the effect that closing can have in this case.
Figure 5.8. Multiple closings for outline smoothing. (a) glyph from Figure 5.7 after a depth 2 closing, (b) after a depth 3 closing.
Most opening and closings use simple structuring element in practice. The traditional approach to computing an opening of depth N is to perform N consecutive binary erosions followed by N binary dilations. This means that computing all of the openings of an image up to depth ten requires that 110 erosions or dilations be performed. If erosion and dilation are implemented in a naive fashion, this will require 220 passes through the image. The alliterative is to save each of the ten erosions of the original image, each of these is then dilated by the proper number of iterations to give the ten opened images. The amount of storage required for the latter option can be prohibitive, and if file storage is used the I/O time
Introduction to Image Processing and Computer Vision by LUONG CHI MAI http://www.netnam.vn/unescocourse/computervision/computer.htm
can be large also.
A fast erosion method is based on the distance map of each object, where the numerical value of each pixel is replaced by a new value representing the distance of that pixel from the nearest background pixel. Pixels on a boundary would have a value of 1, being that they are one pixel width from a background pixel; pixels that are two widths from the background would be given a value of 2, and so on. The result has the appearance of a contour map, where the contours represent the distance from the boundary. For example, the object shown in Figure 5.9a has the distance map shown in Figure 5.9b. The distance map contains enough information to perform an erosion by any number of pixels in just one pass through the image;
in other words, all erosions have been encoded into one image. This globally eroded image can be produced in just two passes through the original image, and a simple thresholding operation will give any desired erosion.
There is also a way, similar to that of global erosion, to encode all possible openings as one gray-level image, and all possible closings can be computed at the same time. First, as in global erosion, the distance map of the image is found. Then all pixels that do NOT have at least one neighbor nearer to the background and one neighbor more distant are located and marked: These will be called nodal pixels. Figure 5.9c shows the nodal pixels associated with the object of Figure 5.9a. If the distance map is thought of as a three-dimensional surface where the distance from the background is represented as height, then every pixel can be thought of as being the peak of a pyramid having a standardized slope. Those peaks that are not included in any other pyramid are the nodal pixels. One way to locate nodal pixels is to scan the distance map, looking at all object pixels; find the minimum (or MIN) and maximum (or MAX) value of all neighbors of the target pixel, and compute MAX-MIN. If this value is less than the maximum possible, which is 2 when using 8-distance, then the pixel is nodal.
Figure 5.9. Erosion using a distance map. (a) A blob as an example of an image to be eroded, (b) The distance map of the blob image, (c) Nodal pixels in this image are shown as periods
(".").
To encode all openings of the object, a digital disk is drawn centered at each nodal point. The pixel values and the extent of the disk are equal to the value the nodal pixel. If a pixel has already been drawn, then it will take on the larger of its current value or the new one being painted. The resulting object has the same outline as the original binary image, so the object can be recreated from the nodal pixels alone. In addition, the gray levels of this globally opened image represent an encoding of all possible openings. As an example, consider the disk shaped object in Figure 5.10a and the corresponding distance map of Figure 5.10b. There
Introduction to Image Processing and Computer Vision by LUONG CHI MAI http://www.netnam.vn/unescocourse/computervision/computer.htm
are nine nodal points: Four have the value 3, and the remainders have the value 5.
Thresholding the encoded image yields an opening having depth equal to the threshold.
Figure 5.10 Global opening of a disk-shaped object. (a) Distance map of the original object.
(b) Nodal pixels identified. (c) Regions grown from the pixels with value 3. (d) Regions grown from pixels with value 5. (e) Globally opened image. (f) Globally opened image drawn
as pixels.
All possible closings can be encoded along with the openings if the distance map is changed to include the distance of background pixels from an object. Closings are coded as values less than some arbitrary central value (say, 128) and openings are coded as values greater than this central value.
Introduction to Image Processing and Computer Vision by LUONG CHI MAI http://www.netnam.vn/unescocourse/computervision/computer.htm