The C++ interface for erode. More...

array erode (const array &image, const array &mask)
 

Detailed Description

The C++ interface for erode.

The erosion function is a morphological transformation on an image that requires two inputs. The first is the image to be morphed, and the second is the mask indicating neighborhood that must be white in order to preserve each pixel.

In erode, for each pixel, the mask is centered at the pixel. If each pixel of the mask matches the corresponding pixel on the image, then no change is made. If there is at least one mismatch, then pixels are changed to the background color (black).

Erosion supports n-channel images (ie. 3D matrices). However a tile must be 2D and will be same for all channels. If you wish to use separate masks for channels, you can extract the channel, apply the operation and store the resulting channel back in the array.

Image erosion is useful for making edges more defined.

// Erode an image, 8-neighbor connectivity
array mask8 = constant(1,3, 3);
array img_out = erode(img_in, mask8);
// erode an image, 4-neighbor connectivity
const float h_mask4[] = { 0.0, 1.0, 0.0,
1.0, 1.0, 1.0,
0.0, 1.0, 0.0 };
array mask4 = array(3, 3, h_mask4);
array img_out = erode(img_in, mask4);
Original
Original
Mask (8-neighbor connectivity)
Mask (8-neighbor connectivity)
Intermediate
Intermediate
Result
Result

For further reference, you can look at the wikipedia page: Erosion (morphology)

Function Documentation

array af::erode ( const array &  image,
const array &  mask 
)
Parameters
[in]imageinput image to be eroded
[in]maskindicating neighborhood to match
Returns
eroded image
Note
mask must be square and odd length (3x3,5x5,7x7,...)
Examples:
examples/image_processing/image_demo.cpp.