Skip to main content

ImageMorphology

ImageMorphology [/E=SE# /I=iterations /L/N/O/R=roiSpec /S= StructureElement /W=whiteValue /X=xOrigin /Y=yOrigin /Z=zOrigin ] Method ImageMatrix

The ImageMorphology operation performs one of several standard image morphology operations on the source ImageMatrix. Unless the /O flag is specified, the resulting image is saved in the wave M_ImageMorph. The operation applies only to waves of type unsigned byte. All ImageMorphology methods except for watershed use a structure element. The structure element may be one of the built-in elements (see /E below) or a user specified element.

Erosion, Dilation, Opening and Closing are the only methods supported for 3D ImageMatrix.

Parameters

Method is one of the following names:

BinaryErosionPerforms an erosion of the source binary image using a built-in or user specified structure element (see /E and /S flags).
BinaryDilationPerforms a dilation of the source binary image using a built-in or user specified structure element (see /E and /S flags).
ClosingPerforms the closing operation (dilation followed by erosion). The same structure element is used in both erosion and dilation. Note that this operation is an idempotent which means that there is no point of executing it more than once.
DilationPerforms a dilation of the source grayscale image using either a built-in structure element or a user specified structure element. The operation supports only 8-bit gray images.
ErosionPerforms an erosion of the source grayscale image using either a built-in structure element or a user specified structure element. The operation supports only 8-bit gray images.
OpeningPerforms an opening operation (erosion followed by dilation). The same structure element is used in both erosion and dilation. Note that this operation is an idempotent which means that there is no point of executing it more than once.
TopHatCalculates the difference between the eroded image and dilated image using the same structure element.
WatershedCalculates the watershed regions for grayscale or binary image. Use the /N flag to mark all nonwatershed lines as NaNs. The /L flag switches from using 4 neighboring pixels (default) to 8 neighboring pixels.

Flags

/DEST=destWUse this flag to designate the destination of the output image. By default ImageMorphology saves the output in the wave M_ImageMorph in the current data folder.
The /DEST flag was added in Igor Pro 10.00.
/FREECreates destW as a free wave. This flag does not affect any of the output waves that are created by default without a user-specified destination.
/FREE is allowed only in functions and only if destW, as specified by /DEST, is a simple name or wave reference structure field.
See Free Waves for more discussion.
The /FREE flag was added in Igor Pro 10.00.
/E=idUse a particular built in structure element. See the table below in Structure Elements for /E for details on built-in structure elements and their id. Make sure to use the appropriate id for the dimensionality of ImageMatrix.
Note that this flag has no effect in watershed calculations.
/I= iterationsRepeat the operation a specified number of times.
/LUse 8-connected neighbors instead of 4.
/NSets the background level to 64 (=NaN)
/OOverwrites the source wave with the output
/R=roiSpecSpecify a region of interest (ROI). The ROI is defined by a wave of type unsigned byte (/b/u). The ROI wave must have the same number of rows and columns as the image wave. The ROI itself is defined by the entries/pixels whose values are 0. Pixels outside the ROI can take any nonzero value. The ROI does not have to be contiguous and can take any arbitrary shape. See ImageGenerateROIMask for more information on creating ROI waves.
In general, the roiSpec has the form {roiWaveName , roiFlag }, where roiFlag can take the following values:
roiFlagMeaning
0set pixels outside the ROI to 0
1set pixels outside the ROI as in original image
2set pixels outside the ROI to NaN (=64)
By default roiFlag is set to 1 and it is then possible to use the /R flag using the abbreviated form /R=roiWave .
/S= seWaveSpecifies your own structure element.
seWave must be of type unsigned byte with pixels that belong to the structure element set to 1 and background pixels set to 0.
There are no limitations on the size of the structure element and you can use the /X and /Y flags to specify the origin of your structure element.
/W= whiteValUse this flag if your white value in the binary image is different than 255. The black level is assumed to be zero.
/X= xOriginSpecifies the X-origin of a user-defined structure element starting at 0. If you do not use this flag Igor sets the origin to the center of the specified structure element.
/Y= yOriginSpecifies the Y-origin of a user-defined structure element starting at 0. If you do not use this flag Igor sets the origin to the center of the specified structure element.
/Z= zOriginThis flag should only be used for 3D structure elements to specify the Z-origin of the element. If you do not use this flag Igor sets the origin to the center of the specified structure element.

Structure Elements for /E

idElementOriginShape
12x2(0,0)square (default)
21x3(1,1)row (in 3x3 square)
33x1(1,1)column (in 3x3 square)
43x3(1,1)cross (in 3x3 square)
55x5(2,2)circle(in 5x5 square)
63x3(1,1)full 3x3 square
2002x2x2(1,1,1)symmetric cube
2022x2x2(1,1,1)2 voxel column in y direction
2032x2x2(1,1,1)2 voxel column in x direction
2042x2x2(1,1,1)2 voxel column in z direction
2052x2x2(1,1,1)XY plane
2062x2x2(1,1,1)YZ plane
2072x2x2(1,1,1)XZ plane
3003x3x3(1,1,1)symmetric cube
3013x3x3(1,1,1)symmetric ball
3023x3x3(1,1,1)3 voxel column in y direction
3033x3x3(1,1,1)3 voxel column in x direction
3043x3x3(1,1,1)3 voxel column in z direction
3053x3x3(1,1,1)XY plane
3063x3x3(1,1,1)YZ plane
3073x3x3(1,1,1)XY plane
5005x5x5(2,2,2)symmetric cube
5015x5x5(2,2,2)symmetric ball
7007x7x7(3,3,3)symmetric cube
7017x7x7(3,3,3)symmetric ball

Examples

If you would like to apply a morphological operation to a wave whose data type is not an unsigned byte and you wish to retain the wave's dynamic range, you can use the following approach:

Function ScaledErosion(inWave)
Wave inWave

WaveStats/Q inWave
Variable nor=255/(V_max-V_min)
MatrixOp/O tmp=nor*(inWave-V_min)
Redimension/B/U tmp
ImageMorphology/E=5 Erosion tmp
Wave M_ImageMorph
MatrixOp/O inWave=(M_ImageMorph/nor)+V_min
KillWaves/Z tmp,M_ImageMorph
End

See Also

Image Processing, Morphological Operations, Particle Analysis.

The ImageGenerateROIMask operation for creating ROIs.