<< dilate | Image filtering | filter2D >>

scicv >> Image filtering > erode

# erode

Erodes an image

### Syntax

    img_out = erode(img_src, element[, anchor[, iterations[, borderType[, borderValue]]]])

### Parameters

img_in

  Input image (Mat).

element

  Structuring element used for erosion (double matrix or Mat) (default 3x3 matrix).

anchor

  Position of the anchor in the element (double 1x2 matrix) (default the anchor is at the element center).

iterations

  number of times erosion is applied (double).

borderType

  Pixel extrapolation method (double) (default `BORDER_DEFAULT`).

borderValue

  Border value (double matrix 1xn n=1..4).

img_out

  Output image (Mat).

### Description

`erode` erodes an image using the specified structuring element giving the pixel neighborhood over which the minimum is taken.

### Examples

    scicv_Init();

    img = imread(getSampleImage("letter.tif"), CV_LOAD_IMAGE_GRAYSCALE);

    subplot(1,2,1);
    matplot(img);

    // convert to black/white and reverse, image information is white pixels (value 1) but we want to erode black pixels (value 0)
    [res, img_bw] = threshold(img, 127, 255, THRESH_BINARY_INV);

    element = getStructuringElement(MORPH_RECT, [5 5]);
    img_erode = erode(img_bw, element);

    // we need to reverse again before display
    img_erode_reverse = bitwise_not(img_erode);

    subplot(1,2,2);
    matplot(img_erode_reverse);

    delete_Mat(img);
    delete_Mat(img_bw);
    delete_Mat(element);
    delete_Mat(img_erode);
    delete_Mat(img_erode_reverse);

### See also

- dilate

Report an issue
<< dilate | Image filtering | filter2D >>