Detecting Peaks of Brightness
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. Run the example procedure by entering morphtophatexample at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT morphtophatexample.pro.
- Prepare the display device and load a grayscale color table:
- Select and open the image file as a grayscale image:
- Get the image dimensions, and add a border for display purposes:
- Get the new dimensions, create a window and display the original image:
- After examining the structures you want to extract from the image (the small bright specks), define a circular structuring element with a small radius:
- Apply MORPH_TOPHAT to the image and display the results:
- Determine an intensity value with which to stretch the image using an intensity histogram as a guide:
- Highlight the brighter image features by displaying a stretched version of the image:
- Create a binary mask of the image to display only the brightest pixels:
file = FILEPATH('r_seeberi_spore.jpg', $
SUBDIRECTORY = ['examples', 'data'])
READ_JPEG, file, img, /GRAYSCALE
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 radiusTip
EnterPRINT, strucElemto view the structure created by the previous statement.
tophatImg = MORPH_TOPHAT(padImg, strucElem) TVSCL, tophatImg, 1The 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, 2Pixels with values greater than 70 are assigned the maximum pixel value (white) and the remaining pixels are scaled across the full range of intensities.

