| Image Processing Toolbox™ | ![]() |
IM2 = imclearborder(IM)
IM2 = imclearborder(IM,conn)
IM2 = imclearborder(IM) suppresses structures that are lighter than their surroundings and that are connected to the image border. (In other words, use this function to clear the image border.) IM can be a grayscale or binary image. The output image, IM2, is grayscale or binary, respectively. The default connectivity is 8 for two dimensions, 26 for three dimensions, and conndef(ndims(BW),'maximal') for higher dimensions.
Note For grayscale images, imclearborder tends to reduce the overall intensity level in addition to suppressing border structures. |
IM2 = imclearborder(IM,conn) specifies the desired connectivity. conn can have any of the following scalar values.
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 0's and 1's. The 1-valued elements define neighborhood locations relative to the center element of conn. Note that conn must be symmetric about its center element.
Note A pixel on the edge of the input image might not be considered to be a border pixel if a nondefault connectivity is specified. 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. |
IM can be a numeric or logical array of any dimension, and it must be nonsparse and real. IM2 has the same class as IM.
The following examples use this simple binary image to illustrate the effect of imclearborder when you specify different connectivities.
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
Using a 4-connected neighborhood, the pixel at (5,2) is not considered connected to the border pixel (4,1), so it is not cleared.
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 0Using an 8-connected neighborhood, pixel (5,2) is considered connected to pixel (4,1) so both are cleared.
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 0imclearborder 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.
[1] Soille, P., Morphological Image Analysis: Principles and Applications, Springer, 1999, pp. 164-165.
![]() | imbothat | imclose | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |