Previous IDL Reference Guide: Procedures and Functions Next

MORPH_TOPHAT

Syntax | Return Value | Arguments | Keywords | Examples | Version History | See Also

The MORPH_TOPHAT function applies the top-hat operator to a grayscale image. The top-hat operator is implemented by first applying the opening operator to the original image, then subtracting the result from the original image. Applying the top-hat operator provides a result that shows the bright peaks within the image.

This routine is written in the IDL language. Its source code can be found in the file morph_tophat.pro in the lib subdirectory of the IDL distribution.

Syntax

Result = MORPH_TOPHAT ( Image, Structure [, PRESERVE_TYPE=bytearray | /UINT | /ULONG] [, VALUES=array] )

Return Value

Returns the resulting one-, two-, or three-dimensional array.

Arguments

Image

A one-, two-, or three-dimensional array upon which the top-hat operation is to be performed.

Structure

A one-, two-, or three-dimensional array to be used as the structuring element. The elements are interpreted as binary values — either zero or nonzero. The structuring element must have the same number of dimensions as the Image argument.

Keywords

PRESERVE_TYPE

Set this keyword to return the same type as the input array. The input array must be of type BYTE, UINT, or ULONG. This keyword only applies for grayscale erosion/dilation, and is mutually exclusive of the UINT and ULONG keywords.

UINT

Set this keyword to return an unsigned integer array. This keyword is mutually exclusive of the ULONG and PRESERVE_TYPE keywords.

ULONG

Set this keyword to return an unsigned longword integer array. This keyword is mutually exclusive of the UINT and PRESERVE_TYPE keywords.

VALUES

An array of the same dimensions as the Structure argument providing the values of the structuring element. If the VALUES keyword is not present, all elements of the structuring element are 0.

Examples

The following example illustrates an application of the top-hat operator to an image in the examples/demo/demodata directory:

; Handle TrueColor displays:  
DEVICE, DECOMPOSED=0  
  
; Read the image  
path=FILEPATH('pollens.jpg',SUBDIR=['examples','demo','demodata'])   
READ_JPEG, path, img  
  
; Create window:  
WINDOW, 0, XSIZE=700, YSIZE=280  
  
; Show original  
XYOUTS, 180, 265, 'Original Image', ALIGNMENT=.5, /DEVICE  
TVSCL, img, 20, 20  
  
; Radius of disc  
r = 2  
  
; Create a binary disc of given radius.  
disc = SHIFT(DIST(2*r+1), r, r) LE r  
  
; Apply top-hat operator  
tophat = MORPH_TOPHAT(img, disc)  
  
; Display stretched result.  
XYOUTS, 520, 265, 'Stretched Result', ALIGNMENT=.5, /DEVICE  
TVSCL, tophat < 50, 360, 20  

 


Note
Also see Detecting Peaks of Brightness.

Version History

5.3
Introduced

See Also

DILATE, ERODE, MORPH_CLOSE, MORPH_DISTANCE, MORPH_GRADIENT, MORPH_HITORMISS, MORPH_OPEN, MORPH_THIN

  IDL Online Help (March 06, 2007)