|IDL Reference Guide: Procedures and Functions|
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.
Result = MORPH_HITORMISS (Image, HitStructure, MissStructure)
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.
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.
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.
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.
It is assumed that the HitStructure and the MissStructure arguments are disjoint.
Also see Selecting Specific Image Objects.
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.
;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 ; 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 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
IDL Online Help (March 06, 2007)