The MORPH_HITORMISS function applies the hit-or-miss operator to a binary image. The hit-or-miss operator is implemented by first applying an erosion operator with a hit structuring element to the original image. Then an erosion operator is applied to the complement of the original image with a secondary miss structuring element. The result is the intersection of the two results.

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

Example


The following code snippet identifies blobs with a radius of at least 2, but less than 4 in the pollen image. These regions totally enclose a disc of radius 2, contained in the 5 x 5 kernel named “hit”, and in turn, fit within a hole of radius 4, contained in the 9 x 9 array named “miss”. Executing this specific example identifies four blobs in the image with these attributes.

The example code is broken into several sections; click on all the sections to execute the code in IDL.

;Handle TrueColor displays:
DEVICE, DECOMPOSED=0
;Read the image
path=FILEPATH('pollens.jpg',SUBDIR=['examples','demo','demodata'])
READ_JPEG, path, img
WINDOW, 0, XSIZE=700, YSIZE=540

Next, display the original image:

; Display the original image
XYOUTS, 180, 525, 'Original Image', ALIGNMENT=.5, /DEVICE
TV, img, 20, 280
rh = 2 ;Radius of hit disc
rm = 4 ;Radius of miss disc
;Create a binary disc of given radius.
hit = SHIFT(DIST(2*rh+1), rh, rh) LE rh
;Complement of disc for miss
miss = SHIFT(DIST(2*rm+1), rm, rm) GT rm
;Load discrete color table
TEK_COLOR
;Apply the threshold
thresh = img GE 140B
 

Display the thresholded image and compute the matches and display them:

; Display the thresholded image
XYOUTS, 520, 525, 'Thresholded Image', ALIGNMENT=.5, /DEVICE
TV, thresh, 360, 280
;Compute matches
matches = MORPH_HITORMISS(thresh, hit, miss)
;Expand matches to size of hit disc
matches = DILATE(matches, hit)
;Show matches.
XYOUTS, 180, 265, 'Matches', ALIGNMENT=.5, /DEVICE
TV, matches, 20, 20
;Superimpose, showing hit regions in blue.
;(Blue = color index 4 for tek_color.)
XYOUTS, 520, 265, 'Superimposed, hit regions in blue',$
   ALIGNMENT=.5, /DEVICE
TV, thresh + 3*matches, 360, 20

Syntax


Result = MORPH_HITORMISS (Image, HitStructure, MissStructure)

Return Value


The resulting image corresponds to the positions where the hit structuring element lies within the image, and the miss structure lies completely outside the image. The two structures must not overlap.

Arguments


Image

A one-, two-, or three-dimensional array upon which the morphological operation is to be performed. The image is treated as a binary image with all nonzero pixels considered as 1.

HitStructure

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

MissStructure

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

Note: It is assumed that the HitStructure and the MissStructure arguments are disjoint.

Keywords


None.

Version History


5.3

Introduced

See Also


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