Matlab去除二值图像小对象 bwareaopen

本文介绍了一种图像处理技术,即面积开运算,用于从二值图像中去除小对象。通过设定像素阈值,该操作能有效清除不重要的细节,保持图像的主要特征。文章提供了使用MathWorks MATLAB实现的具体示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

From: https://ww2.mathworks.cn/help/images/ref/bwareaopen.html

bwareaopen

Remove small objects from binary image

collapse all in page

Syntax

BW2 = bwareaopen(BW,P)

BW2 = bwareaopen(BW,P,conn)

Description

example

BW2 = bwareaopen(BW,P) removes all connected components (objects) that have fewer than P pixels from the binary image BW, producing another binary image, BW2. This operation is known as an area opening.

BW2 = bwareaopen(BW,P,conn) removes all connected components, where conn specifies the desired connectivity.

Examples

collapse all

Remove Objects in Image Containing Fewer Than 50 Pixels

Try This Example

Read binary image.

BW = imread('text.png');

Remove objects containing fewer than 50 pixels using bwareaopen function.

BW2 = bwareaopen(BW, 50);

Display original image next to morphologically opened image.

imshowpair(BW,BW2,'montage')

Input Arguments

collapse all

BW — Binary image
real, nonsparse, logical or numeric array of any dimension

Binary image, specified as a nonsparse, logical or numeric array of any dimension.

Example: BW2 = bwareaopen(BW, 50);

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

P — Maximum number of pixels in objects
nonnegative, integer-valued, numeric scalar

Maximum number of pixels in objects, specified as a nonnegative, integer-valued, numeric scalar.

Example: BW2 = bwareaopen(BW, 50);

Data Types: double

conn — Pixel connectivity
4 | 8 | 6 | 18 | 26 | 3-by-3-by- ... -by-3 matrix of 0s and 1s

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. Two adjoining pixels are part of the same object if they are both on and are connected along the horizontal or vertical direction.

8-connected

Pixels are connected if their edges or corners touch. Two adjoining pixels are part of the same object if they are both on and are connected along the horizontal, vertical, or diagonal direction.

Three-Dimensional Connectivities

6-connected

Pixels are connected if their faces touch. Two adjoining pixels are part of the same object if they are both on and are connected in:

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

 

18-connected

Pixels are connected if their faces or edges touch. Two adjoining pixels are part of the same object if they are both on and are connected 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. Two adjoining pixels are part of the same object if they are both on and are connected 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, bwareaopen uses the default value conndef(ndims(BW),'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.

Data Types: double | logical

Output Arguments

collapse all

BW2 — Image that has been morphologically opened
nonsparse, logical array of any dimension

Image that has been morphologically opened, specified as a nonsparse, logical array the same size as BW.

Algorithms

The basic steps are

  1. Determine the connected components:

    CC = bwconncomp(BW, conn);
  2. Compute the area of each component:

    S = regionprops(CC, 'Area');
  3. Remove small objects:

    L = labelmatrix(CC);
    BW2 = ismember(L, find([S.Area] >= P));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值