This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

imclearborder

Suppress light structures connected to image border

Syntax

J = imclearborder(I)
J = imclearborder(I,conn)

Description

example

J = imclearborder(I) suppresses structures in image I that are lighter than their surroundings and that are connected to the image border. Use this function to clear the image border. For grayscale images, imclearborder tends to reduce the overall intensity level in addition to suppressing border structures. The output image, J, is grayscale or binary, depending on the input.

example

J = imclearborder(I,conn) specifies the pixel connectivity, conn.

Examples

collapse all

Create a 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 = 9×9

     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

Now 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 = 9×9

     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

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

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

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

Pixel connectivity, specified as one of the values in this table. The default connectivity is 8 for 2-D images, and 26 for 3-D images.

Value

Meaning

Two-Dimensional Connectivities

4-connected

Pixels are connected if their edges touch. The neighborhood of a pixel are the adjacent pixels in the horizontal or vertical direction.

8-connected

Pixels are connected if their edges or corners touch. The neighborhood of a pixel are the adjacent pixels in the horizontal, vertical, or diagonal direction.

Three-Dimensional Connectivities

6-connected

Pixels are connected if their faces touch. The neighborhood of a pixel are the adjacent pixels in:

  • One of these directions: in, out, left, right, up, and down

18-connected

Pixels are connected if their faces or edges touch. The neighborhood of a pixel are the adjacent pixels in:

  • One of these directions: in, out, left, right, up, and down

  • A combination of two directions, such as right-down or in-up

26-connected

Pixels are connected if their faces, edges, or corners touch. The neighborhood of a pixel are the adjacent pixels in:

  • One of these directions: in, out, left, right, up, and down

  • A combination of two directions, such as right-down or in-up

  • A combination of three directions, such as in-right-up or in-left-down

For higher dimensions, imclearborder uses the default value conndef(ndims(I),'maximal').

Connectivity can also be defined in a more general way for any dimension by specifying 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 about its center element. See Specifying Custom Connectivities for more information.

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.

Data Types: double | logical

Output Arguments

collapse all

Processed grayscale or binary image, returned as numeric or logical array, depending on the input image you specify.

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.

Extended Capabilities

See Also

Introduced before R2006a