|
Image Processing : Extracting and Analyzing Shapes |
|
The MORPH_DISTANCE function computes a grayscale, N-dimensional distance map from a binary image. The map shows, for each foreground pixel, the distance to the nearest background pixel using a given norm. The norm simply defines how neighboring pixels are sampled. See the MORPH_DISTANCE description in the IDL Reference Guide for full details. The resulting values in the grayscale image denote the distance from the surveyed pixel to the nearest background pixel. The brighter the pixel, the farther it is from the background.
The following example applies the distance transformation to a grayscale image of a cultured sample of Neocosmospora vasinfecta, a common fungal plant pathogen. Complete the following steps for a detailed description of the process.
| Example Code See morphdistanceexample.pro in the examples/doc/image subdirectory of the IDL installation directory for code that duplicates this example. |
DEVICE, DECOMPOSED = 0, RETAIN = 2 LOADCT, 0
file = FILEPATH('n_vasinfecta.jpg', $
SUBDIRECTORY = ['examples', 'data'])
READ_JPEG, file, img, /GRAYSCALE
dims = SIZE(img, /DIMENSIONS) padImg = REPLICATE(0B, dims[0]+10, dims[1]+10) padImg[5,5] = img
dims = SIZE(padImg, /DIMENSIONS) WINDOW, 0, XSIZE = 2*dims[0], YSIZE = 2*dims[1], $ TITLE='Distance Map and Overlay of Binary Image' TVSCL, padImg, 0
WINDOW, 2, XSIZE = 400, YSIZE = 300 PLOT, HISTOGRAM(padImg)
| Note Using an intensity histogram as a guide for determining intensity values is described in the section, Determining Intensity Values for Threshold and Stretch. |
binaryImg = padImg LT 120 WSET, 0 TVSCL, binaryImg, 1
The original image (left) and binary image (right) appear in the following figure.
![]() |
distanceImg = MORPH_DISTANCE(binaryImg, $ NEIGHBOR_SAMPLING = 1) TVSCL, distanceImg, 2
distanceImg [WHERE (binaryImg EQ 0)] = MAX(distanceImg) TVSCL, distanceImg, 3
The distance map (left) and resulting blended image (right) show the distance of each image element pixel from the background.
IDL Online Help (March 06, 2007)