imclearborder
Suppress light structures connected to image border
Description
suppresses
structures in image J
= imclearborder(I
)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.
Examples
Impact of Connectivity on Clearing the Border
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
I
— Grayscale or binary image
numeric array | logical array
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
conn
— Pixel connectivity
4
| 8
| 6
| 18
| 26
| 3-by-3-by- ... -by-3 matrix of 0
s and
1
s
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 | ||
| Pixels are connected if their edges touch. The neighborhood of a pixel are the adjacent pixels in the horizontal or vertical direction. |
Current pixel is shown in gray. |
| 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. |
Current pixel is shown in gray. |
Three-Dimensional Connectivities | ||
| Pixels are connected if their faces touch. The neighborhood of a pixel are the adjacent pixels in:
|
Current pixel is shown in gray. |
| Pixels are connected if their faces or edges touch. The neighborhood of a pixel are the adjacent pixels in:
|
Current pixel is center of cube. |
| Pixels are connected if their faces, edges, or corners touch. The neighborhood of a pixel are the adjacent pixels in:
|
Current pixel is center of cube. |
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
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. 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
J
— Processed image
numeric array | logical array
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
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
imclearborder
supports the generation of C code (requires MATLAB® Coder™). Note that if you choose the genericMATLAB Host Computer
target platform,imclearborder
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 Types of Code Generation Support in Image Processing Toolbox.Supports only up to 3-D inputs.
The optional second input argument,
conn
, must be a compile-time constant.
Version History
Introduced before R2006a
See Also
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)