The MORPH_OPEN function applies the opening operator to a binary or grayscale image. MORPH_OPEN is an erosion operation followed by a dilation operation. The opening operation is an idempotent operator, applying it more than once produces no further effect.

An alternative definition of the opening, is that it is the union of all sets containing the structuring element in the original image. Both the opening and the closing operators have the effect of smoothing the image, with the opening operation removing pixels, and the closing operation adding pixels.

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

Examples


The following code reads a data file in the IDL Demo data directory containing an magnified image of grains of pollen. It then applies a threshold and a morphological opening operator with a 3 by 3 square kernel to the original image. Notice that much of the irregular borders of the grains have been smoothed by the opening operator.

; 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=540
;Show original image
XYOUTS, 180, 525, 'Original Image', ALIGNMENT=.5, /DEVICE
TV, img, 20, 280
;Apply the threshold
thresh = img GE 140B
;Load a simple color table
TEK_COLOR
;Display edges
XYOUTS, 520, 525, 'Edges', ALIGNMENT=.5, /DEVICE
TV, thresh, 360, 280
;Apply opening operator
open = MORPH_OPEN(thresh, REPLICATE(1,3,3))
;Show the result
XYOUTS, 180, 265, 'Opening Operator', ALIGNMENT=.5, /DEVICE
TV, open, 20, 20
;Show pixels that have been removed in white
XYOUTS, 520, 265, 'Removed Pixels in White', ALIGNMENT=.5, /DEVICE
TV, open + thresh, 360, 20

Syntax


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

Return Value


The result of an opening operation is that small features (e.g., noise) within the image are removed, yet the original sizes of the primary foreground features are maintained.

Arguments


Image

A one-, two-, or three-dimensional array upon which the opening operation is to be performed. If neither of the keywords GRAY or VALUES is present, the image is treated as a binary image with all nonzero pixels considered as 1.

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


GRAY

Set this keyword to perform a grayscale, rather than binary, operation. Nonzero elements of the Structure parameter determine the shape of the structuring element. If the VALUES keyword is not present, all elements of the structuring element are 0.

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 only applies for grayscale operations, and is mutually exclusive of the ULONG and PRESERVE_TYPE keywords.

ULONG

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

VALUES

An array of the same dimensions as Structure providing the values of the structuring element. The presence of this keyword implies a grayscale operation.

Version History


5.3

Introduced

See Also


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