[Top] [Up] [Prev] [Next] [Up] [Tutorial] mmtutor V1.0 30abr2001

mm045residues - Residues.


Synopsis
mm045residues
Description

Residues

The residue is a generic name for what is left something is removed. For instance if we clean or filter something, the residue is what did not pass on the filter. As long as we have two operators, one larger that the other, the residue can be computed by their difference.

equation

Morphological Gradient

One first group of residues are called gradient and are obtained from the dilations and erosions. They generate contours (binary or gray scale), that can be internal (original minus the erosion), external (dilation minus the original) or both (dilation minus erosion).

Contour of Binary Images

In the example below, the gradients of a binary image are computed using the elementary cross (3x3) structuring element. Observe that the internal gradient is the internal contour and the external is the external contour of the blobs.

F=imread('blob3.tif');
G=mmgradm(F,mmsecross,mmsecross);
Gi=mmgradm(F,mmsecross(0),mmsecross);
Ge=mmgradm(F,mmsecross,mmsecross(0));
mmshow(F);
mmshow(G);
image
(F)
image
(G)
mmshow(Gi);
mmshow(Ge);
image
(Gi)
image
(Ge)

By changing the size and shape of the structuring element, different results can be obtained. In the example below, an internal contour of thickness 5 is computed using the internal gradient of a disk of radius 5.

F=imread('blob3.tif');
Gt=mmgradm(F,mmsedisk(0),mmsedisk(5));
mmshow(F);
mmshow(Gt);
image
(F)
image
(Gt)

Internal Gradient for Gray Scale Images

Similarly, the gradients can be applied to gray scale image. The example below computes the internal gradient of a gray scale image using the elementary cross.

f=(imread('danaus.tif'));
mmshow(f);
g=mmgradm(f,mmsecross(0),mmsecross);
mmshow(g);
image
(f)
image
(g)

Top-Hat

The second category of residues are the open and close top-hat. In this case, the opening and the closing are morphological filters geared by the shape of the structuring element. The residues are everything that the structuring element did not fit. The open top-hat is the difference between the original and the opened image and the close top-hat is the difference between the close and the original.

Open Top-Hat for Binary Images

As the open removes narrow protuberances or spikes on the contour, the open top-hat reveals exactly these protuberances that the structuring element does not fit. Here is a simple demonstration to detect the teeth of a gear.

Open Top-Hat for Gray Scale Signals)

For gray scale signals, the open top-hat detects the peaks that are narrower than the width of the structuring element. In the example below, a signal with three gaussian peaks of different widths is generated (in black), the opened signal appears in red and the top hat is displayed in blue.

x=0:69;
f1 = uint8(200 * exp(-((x-20)/10).^2));
f2 = uint8(120 * exp(-((x-40)/20).^2));
f3 = uint8(250 * exp(-((x-60)/4) .^2));
f=mmunion(f1,f2,f3);
go = mmopen(f,mmseline(7));
gth= mmsubm(f,go);
g=plot(f);
plot(x,f,'k', x,go,'r', x,gth,'b');
image
(f)
image
(f,go,gth)

Open Top-Hat for Gray Scale Images

For bidimensional gray scale images, we can see the behavior of the opening top-hat in the three gaussian-shaped peaks sinthetic image. The opening used a box of radius 3 (7x7) and all peaks in the image in which the SE cannot fit from beneath are detected by the top hat.

f=imread('ggray.tif');
gth=mmopenth(f,mmsebox(3));
mmshow(f);
mmshow(gth);
image
(f)
image
(gth)
mmshow(mmsurf(f));
mmshow(mmsurf(gth));
image
(mmsurf(f))
image
(mmsurf(gth))
mmsurfshow(f);
mmsurfshow(gth);
image
(f)
image
(gth)

Gray Scale Open Top-Hat for Background Shading Removal

In the didactical example below, a binary text image is corrupted by a background shading ramp. The opening by a structuring element larger than the widest element of the text characters will filter out all the text features. The open top hat will detect the residues, which is the target for this demonstration.

f=imread('nshading.tif');
B=mmsebox(2);
go=mmopen(f,B);
gth=mmopenth(f,B);
mmshow(f);
mmshow(go);
mmshow(gth);
image
(f)
image
(go)
image
(gth)

Although this example was generated artificially, this methodology is very powerful and there are many successful image segmentation applications using top hat followed by a thresholding. The top hat removes the background noise and the thresholding selects the strongest features. This composed operations (top hat and the thresholding) can be seen as a very powerful adaptive thresholding. Actually, the original top-hat was proposed this way. Later, the term top hat become popular to call it just for the residue of the opening.

Application of gray-scale closing top-hat for defect detection

This is an illustration of the power of the top hat followed by a thresholding as an image segmentation tool. The idea is to detect faults in a microelectronic image of vertical stripes. The closing top-hat by vertical structuring element can enhance them for later selection using thresholding.

Demo: mmdlith

Exercises


[Top] [Up] [Prev] [Next] [Up] [Tutorial] Valid XHTML 1.0!
Copyright (c) 1998-20001 by SDC Information SystemsCopyright (c) 1998-20001 by SDC Information Systems