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.

  1. Prepare the display device and load a grayscale color table:
  2. DEVICE, DECOMPOSED = 0, RETAIN = 2 
    LOADCT,0 
    
  3. Select and open the image file as a grayscale image:
  4. file = FILEPATH('r_seeberi_spore.jpg', $ 
        SUBDIRECTORY = ['examples', 'data']) 
    READ_JPEG, file, img, /GRAYSCALE 
    
  5. Get the image dimensions, and add a border for display purposes:
  6. dims = SIZE(img, /DIMENSIONS) 
    padImg = REPLICATE(0B, dims[0]+10, dims[1]+10) 
    padImg [5,5] = img 
    
  7. Get the new dimensions, create a window and display the original image:
  8. dims = SIZE(padImg, /DIMENSIONS) 
    WINDOW, 1, XSIZE = 2*dims[0], YSIZE = 2*dims[1], $ 
        TITLE = 'Detecting Small Features with MORPH_TOPHAT' 
    TVSCL, padImg, 0 
    
  9. After examining the structures you want to extract from the image (the small bright specks), define a circular structuring element with a small radius:
  10. 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.

  11. Apply MORPH_TOPHAT to the image and display the results:
  12. 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).

    Figure 9-10: Original (left) and Top-hat Image (right)

    imgmorph10.gif

  13. Determine an intensity value with which to stretch the image using an intensity histogram as a guide:
  14. 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.

  15. Highlight the brighter image features by displaying a stretched version of the image:
  16. 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.

  17. Create a binary mask of the image to display only the brightest pixels:
  18. 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.

    Figure 9-11: Stretched Top-hat Image (left) and Binary Mask (right)

    imgmorph11.gif