|
Image Processing : Extracting and Analyzing Shapes |
|
The MORPH_GRADIENT function applies the gradient operation to a grayscale image. This operation highlights object edges by subtracting an eroded version of the original image from a dilated version. Repeatedly applying the gradient operator or increasing the size of the structuring element results in wider edges.
The following example extracts image features by applying the morphological gradient operation to an image of the Mars globe. Complete the following steps for a detailed description of the process.
| Example Code See morphgradientex.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('marsglobe.jpg', $
SUBDIRECTORY=['examples', 'data'])
READ_JPEG, file, image, /GRAYSCALE
dims = SIZE(image, /DIMENSIONS) WINDOW, 0, XSIZE =2*dims[0], YSIZE = 2*dims[1], $ TITLE = 'Original and MORPH_GRADIENT Images'
The original image is shown in the following figure.
radius = 1 strucElem = SHIFT(DIST(2*radius+1), radius, radius) LE radius
| Tip Enter PRINT, strucElem to view the structure created by the previous statement. |
morphImg = MORPH_GRADIENT(image, strucElem) TVSCL, morphImg, 2
WINDOW, 2, XSIZE = 400, YSIZE = 300 PLOT, HISTOGRAM(1-image)
The previous line returns a histogram of an inverse of the original image since the final display will also be an inverse display for showing the greatest detail.
WSET, 0 TVSCL, 1-(morphImg < 87 ), 3
The following figure displays the initial and stretched gradient images.
IDL Online Help (March 06, 2007)