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.
DEVICE, DECOMPOSED=0
path=FILEPATH('pollens.jpg',SUBDIR=['examples','demo','demodata'])
READ_JPEG, path, img
WINDOW, 0, XSIZE=700, YSIZE=540
Next, display the original image:
XYOUTS, 180, 525, 'Original Image', ALIGNMENT=.5, /DEVICE
TV, img, 20, 280
rh = 2 rm = 4 hit = SHIFT(DIST(2*rh+1), rh, rh) LE rh
miss = SHIFT(DIST(2*rm+1), rm, rm) GT rm
TEK_COLOR
thresh = img GE 140B
Display the thresholded image and compute the matches and display them:
XYOUTS, 520, 525, 'Thresholded Image', ALIGNMENT=.5, /DEVICE
TV, thresh, 360, 280
matches = MORPH_HITORMISS(thresh, hit, miss)
matches = DILATE(matches, hit)
XYOUTS, 180, 265, 'Matches', ALIGNMENT=.5, /DEVICE
TV, matches, 20, 20
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
See Also
DILATE, ERODE, MORPH_CLOSE, MORPH_DISTANCE, MORPH_GRADIENT, MORPH_OPEN, MORPH_THIN, MORPH_TOPHAT