Documentation

imclearborder

Suppress light structures connected to image border

Syntax

Description

example

IM2 = imclearborder(IM) suppresses structures that are lighter than their surroundings and that are connected to the image border. Use this function to clear the image border. IM can be a grayscale or binary image. For grayscale images, imclearborder tends to reduce the overall intensity level in addition to suppressing border structures. The output image, IM2, is grayscale or binary, depending on the input. The default connectivity is 8 for two dimensions, 26 for three dimensions, and conndef(ndims(BW),'maximal') for higher dimensions.

This function supports code generation (see Tips).

example

IM2 = imclearborder(IM,conn) specifies the desired connectivity.

Examples

collapse all

Impact of Connectivity on Clearing the Border

Create simple binary image.

BW = [0     0     0     0     0     0     0     0     0
      0     0     0     0     0     0     0     0     0
      0     0     0     0     0     0     0     0     0
      1     0     0     1     1     1     0     0     0
      0     1     0     1     1     1     0     0     0
      0     0     0     1     1     1     0     0     0
      0     0     0     0     0     0     0     0     0
      0     0     0     0     0     0     0     0     0
      0     0     0     0     0     0     0     0     0];

Clear pixels on the border of the image using 4-connectivity. Note that imclearborder does not clear the pixel at (5,2) because, with 4-connectivity, it is not considered connected to the border pixel at (4,1).

BWc1 = imclearborder(BW,4)
BWc1 =
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     1     1     1     0     0     0
     0     1     0     1     1     1     0     0     0
     0     0     0     1     1     1     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0

Clear pixels on the border of the image using 8-connectivity. imclearborder clears the pixel at (5,2) because, with 8-connectivity, it is considered connected to the border pixel (4,1).

BWc2 = imclearborder(BW,8)
BWc2 =

     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     1     1     1     0     0     0
     0     0     0     1     1     1     0     0     0
     0     0     0     1     1     1     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0

Input Arguments

collapse all

IM — Grayscale or binary imagereal, nonsparse, numeric or logical array

Grayscale or binary image, specified as a real, nonsparse, numeric or logical array.

Example: I = imread('pout.tif'); I2 = imclearborder(I);

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical

conn — Connectivity8 (for 2-D) (default) | 4 | 6 | 18 | 26 | 3-by-3-by- ... -by-3 matrix

Connectivity, specified as one of the values in this table.

Value

Meaning

Two-dimensional connectivities

4

4-connected neighborhood

8

8-connected neighborhood

Three-dimensional connectivities

6

6-connected neighborhood

18

18-connected neighborhood

26

26-connected neighborhood

Connectivity can also be defined in a more general way for any dimension by using for conn a 3-by-3-by- ... -by-3 matrix of 0s and 1s. The 1-valued elements define neighborhood locations relative to the center element of conn. Note that conn must be symmetric around its center element.

    Note   A pixel on the edge of the input image might not be considered to be a border pixel if you specify a nondefault connectivity. For example, if conn = [0 0 0; 1 1 1; 0 0 0], elements on the first and last row are not considered to be border pixels because, according to that connectivity definition, they are not connected to the region outside the image.

Example: I2 = imclearborder(I,4);

Data Types: double | logical

Output Arguments

collapse all

IM2 — Grayscale or binary imagereal, nonsparse, numeric or logical array

Grayscale or binary image, returned as a real, nonsparse, numeric or logical array, depending on the input image you specify.

More About

collapse all

Tips

  • This function supports the generation of C code using MATLAB® Coder™. Note that if you choose the generic MATLAB Host Computer target platform, the function generates code that uses a precompiled, platform-specific shared library. Use of a shared library preserves performance optimizations but limits the target platforms for which code can be generated. For more information, see Understanding Code Generation with Image Processing Toolbox.

    When generating code, note:

    • Supports only up to 3-D inputs.

    • The optional second input argument, conn, must be a compile-time constant.

Algorithms

imclearborder uses morphological reconstruction where:

  • Mask image is the input image.

  • Marker image is zero everywhere except along the border, where it equals the mask image.

References

[1] Soille, P., Morphological Image Analysis: Principles and Applications, Springer, 1999, pp. 164-165.

See Also

Was this topic helpful?