imerode() - Image Processing
IM2 = imerode(IM,SE) erodes the grayscale,
binary, or packed binary image IM, returning the
eroded image IM2. The argument SE is
a structuring element object or array of structuring element objects
returned by the strel or offsetstrel functions. If IM is logical and the structuring element
is flat, imerode performs binary erosion; otherwise
it performs grayscale erosion. If SE is an array
of structuring element objects, imerode performs
multiple erosions of the input image, using each structuring element
in SE in succession. IM2 = imerode(IM,NHOOD) erodes the image IM,
where NHOOD is an array of 0's
and 1's that specifies the structuring element
neighborhood. This is equivalent to the syntax imerode(IM,strel(NHOOD)).
The imerode function determines the center element
of the neighborhood by floor((size(NHOOD)+1)/2).IM2 = imerode(___,PACKOPT,M) specifies
whether IM is a packed binary image and, if it
is, provides the row dimension M of the original
unpacked image. PACKOPT can have either of the
following values. Default value is enclosed in braces ({}).ValueDescription
'ispacked'IM is treated as a packed binary image
as produced by bwpack. IM must
be a 2-D uint32 array and SE must
be a flat 2-D structuring element.
{'notpacked'}IM is treated as a normal array.
If PACKOPT is 'ispacked',
you must specify a value for M.IM2 = imerode(___,SHAPE) specifies
the size of the output image. SHAPE can have either
of the following values. Default value is enclosed in braces ({}).
ValueDescription
{'same'}Make the output image the same size as the input image.
If the value of PACKOPT is 'ispacked', SHAPE must
be 'same'.
'full'Compute the full erosion.
gpuarrayIM2 = imerode(gpuarrayIM,___) performs
the operation on a graphics processing unit (GPU). gpuarrayIM is
a gpuArray that contains a grayscale or binary
image. gpuarrayIM2 is a gpuArray of
the same class as the input image. Note that the PACKOPT syntax
is not supported on a GPU. This syntax requires the Parallel Computing Toolbox™.Code Generation support:
Yes.MATLAB Function Block support:
Yes.
Syntax
IM2 = imerode(IM,SE)IM2 = imerode(IM,NHOOD)IM2 = imerode(___,PACKOPT,M)IM2 = imerode(___,SHAPE)gpuarrayIM2 = imerode(gpuarrayIM,___)
Example
Erode Binary Image with Line Structuring ElementOpen This Example
Read binary image into the workspace.originalBW = imread('text.png');
Create a flat, line-shaped structuring element.se = strel('line',11,90);
Erode the image with the structuring element.erodedBW = imerode(originalBW,se);
View the original image and the eroded image.figure
imshow(originalBW)
figure
imshow(erodedBW)
Erode Grayscale Image with Rolling BallOpen This Example
Read grayscale image into the workspace.originalI = imread('cameraman.tif');
Create a nonflat offsetstrel object.se = offsetstrel('ball',5,5);
Erode the image.erodedI = imerode(originalI,se);
Display original image and eroded image.figure
imshow(originalI)
figure
imshow(erodedI)
Erode Binary Image on GPURead binary image into the workspace.originalBW = imread('text.png');
Create a structuring element.se = strel('line',11,90);
erodedBW = imerode(gpuArray(originalBW),se);
figure, imshow(originalBW), figure, imshow(erodedBW)Erode the image, creating a GPUarray.erodedBW = imerode(gpuArray(originalBW),se);
Display the original image and the eroded image.figure, imshow(originalBW), figure, imshow(erodedBW)
Erode Grayscale Image on GPURead grayscale image into the workspace.originalI = imread('cameraman.tif');
Create a structuring element.se = strel('disk',5);
Erode the image, creating a GPUarray.erodedI = imerode(gpuArray(originalI),se);
Display the original image and the eroded image.figure
imshow(originalI)
figure
imshow(erodedI)Erode MRI Stack Volume Using Cubic Structuring ElementOpen This Example
Create a binary volume.load mristack
BW = mristack < 100;
Create a cubic structuring element.se = strel('cube',3)
se =
strel is a cube shaped structuring element with properties:
Neighborhood: [3x3x3 logical]
Dimensionality: 3
Erode the volume with a cubic structuring element.erodedBW = imerode(BW, se);
Output / Return Value
Limitations
Alternatives / See Also
Reference