Welcome to the L3 Harris Geospatial documentation center. Here you will find reference guides and help documents.
﻿
>  Docs Center  >  IDL Reference  >  Math - Image Processing  >  MORPH_GRADIENT

The MORPH_GRADIENT function applies the morphological gradient operator to a grayscale image. MORPH_GRADIENT is the subtraction of an eroded version of the original image from a dilated version of the original image.

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

## Examples

The following code reads a data file in the IDL Demo data directory containing a magnified image of grains of pollen. It then creates disc of radius 2, in a 5 by 5 array, with all elements within a radius of 2 from the center set to 1. This disc is used as the structuring element for the morphological gradient which is then displayed as both a gray scale image, and as a thresholded image.

`;Handle TrueColor displays:DEVICE, DECOMPOSED=0;Read the imagepath=FILEPATH('pollens.jpg',SUBDIR=['examples','demo','demodata']) READ_JPEG, path, img; Create window:WINDOW, 0, XSIZE=700, YSIZE=540;Show original imageXYOUTS, 180, 525, 'Original Image', ALIGNMENT=.5, /DEVICETVSCL, img, 20, 280;Define disc radiusr = 2;Create a binary disc of given radius.disc = SHIFT(DIST(2*r+1), r, r) LE rbdisc = MORPH_GRADIENT(img, disc);Show edgesXYOUTS, 520, 525, 'Edges', ALIGNMENT=.5, /DEVICETVSCL, bdisc, 360, 280;Show thresholded edgesXYOUTS, 180, 265, 'Threshold Edges', ALIGNMENT=.5, /DEVICETVSCL, bdisc ge 100, 20, 20`

## Syntax

Result = MORPH_GRADIENT (Image, Structure [, PRESERVE_TYPE=bytearray | /UINT | /ULONG] [, VALUES=array] )

## Return Value

The practical result of a morphological gradient operation is that the boundaries of features are highlighted.

## Arguments

### Image

A one-, two-, or three-dimensional array upon which the morphological gradient operation is to be performed.

### Structure

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

## Keywords

### PRESERVE_TYPE

Set this keyword to return the same type as the input array. The input array must be of type BYTE, UINT, or ULONG. This keyword only applies for grayscale erosion/dilation, and is mutually exclusive of the UINT and ULONG keywords.

### UINT

Set this keyword to return an unsigned integer array. This keyword is mutually exclusive of the ULONG and PRESERVE_TYPE keywords.

### ULONG

Set this keyword to return an unsigned longword integer array. This keyword is mutually exclusive of the UINT and PRESERVE_TYPE keywords.

### VALUES

An array of the same dimensions as the Structure argument providing the values of the structuring element. If the VALUES keyword is not present, all elements of the structuring element are 0.

## Version History

 5.3 Introduced