|
Image Processing : Extracting and Analyzing Shapes |
|
The morphological top-hat operation, MORPH_TOPHAT, is also known as a peak detector. This operator extracts only the brightest pixels from the original grayscale image by first applying an opening operation to the image and then subtracting the result from the original image. The top-hat operation is especially useful when identifying small image features with high levels of brightness.
The following example applies the top-hat operation to an image of a mature Rhinosporidium seeberi sporangium (spore case) with endospores. The circular endospores will be extracted using a small disk-shaped structuring element. The top-hat morphological operation effectively highlights the small bright endospores within the image. Complete the following steps for a detailed description of the process.
| Example Code See morphtophatexample.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
DEVICE, DECOMPOSED = 0, RETAIN = 2 LOADCT,0
file = FILEPATH('r_seeberi_spore.jpg', $
SUBDIRECTORY = ['examples', 'data'])
READ_JPEG, file, img, /GRAYSCALE
dims = SIZE(img, /DIMENSIONS) padImg = REPLICATE(0B, dims[0]+10, dims[1]+10) padImg [5,5] = img
dims = SIZE(padImg, /DIMENSIONS) WINDOW, 1, XSIZE = 2*dims[0], YSIZE = 2*dims[1], $ TITLE = 'Detecting Small Features with MORPH_TOPHAT' TVSCL, padImg, 0
radius = 3 strucElem = SHIFT(DIST(2*radius+1), radius, radius) LE radius
| Tip Enter PRINT, strucElem to view the structure created by the previous statement. |
tophatImg = MORPH_TOPHAT(padImg, strucElem) TVSCL, tophatImg, 1
The following figure shows the original image (left) and the peaks of brightness that were detected after the top-hat operation subtracted an opened image from the original image (right).
![]() |
WINDOW, 2, XSIZE = 400, YSIZE = 300 PLOT, HISTOGRAM(padImg)
| Note Using an intensity histogram as a guide for determining intensity values is described in the section, Determining Intensity Values for Threshold and Stretch. |
stretchImg = tophatImg < 70 WSET, 0 TVSCL, stretchImg, 2
Pixels with values greater than 70 are assigned the maximum pixel value (white) and the remaining pixels are scaled across the full range of intensities.
threshImg = tophatImg GE 60 TVSCL, threshImg, 3
The stretched top-hat image (left) and the image after applying a binary mask (right) are shown in the following figure. The endospores within the image have been successfully highlighted and extracted using the MORPH_TOPHAT function.
IDL Online Help (March 06, 2007)