Main Content

bwselect

Select objects in binary image

Description

BW2= bwselect(BW,c,r)returns a binary image containing the objects that overlap the pixel (r,c). Objects are connected sets ofonpixels, that is, pixels having a value of1.

example

BW2= bwselect(BW,c,r,n)also specifies the object connectivity,n, as 4-connected or 8-connected.

[BW2,idx] = bwselect(___)returns the linear indices of the pixels belonging to the selected objects.

[x,y,BW2,idx,xi,yi] = bwselect(___)returns thexandyextents of the image and the (xi,yi) coordinates of the pixels. By default,bwselectuses the intrinsic coordinate system so thatxandyare the imageXDataandYData.

[___] = bwselect(x,y,BW,xi,yi,n)establishes a nondefault world coordinate system forBWfrom the vectorsxandy. The argumentsxiandyispecify pixel coordinates in the world coordinate system.

[___] = bwselect(BW,n)displays the imageBWin a figure and lets you select the (r,c) coordinates interactively using the mouse. With this syntax and the other interactive syntax,bwselectblocks the MATLAB®command line until you finish selecting points.

informa的更多tion about selecting points interactively, seeInteractive Behavior.

[___] = bwselectwithout an input argument lets you select the (r,c) coordinates of the image in the current axes interactively.

例子

collapse all

Select objects in a binary image and create a new image containing only those objects.

Read binary image into the workspace.

BW = imread('text.png');

Specify the locations of objects in the image using row and column indices.

c= [43 185 212]; r = [38 68 181];

Create a new binary image containing only the selected objects. This example specifies 4-connected objects.

BW2 = bwselect(BW,c,r,4);

Display the original image and the new image side-by-side.

imshowpair(BW,BW2,'montage');

Figure contains an axes object. The axes object contains an object of type image.

Input Arguments

collapse all

Binary image, specified as a 2-D numeric matrix or 2-D logical matrix.

Example:BW = imread('text.png');

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

Column index, specified as a numeric scalar or numeric vector. Ifrandcare equal-length vectors, thenBW2contains the sets of objects overlapping with any of the pixels(r(k),c(k)).

Example:c= [43 185 212];

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

Row index, specified as a numeric scalar or numeric vector. Ifrandcare equal-length vectors, thenBW2contains the sets of objects overlapping with any of the pixels(r(k),c(k)).

Example:r = [38 68 181];

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

Connectivity, specified as4or8.

Value Description
4 4-connected objects
8 8-connected objects

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

Worldx-axis coordinates, specified as a numeric scalar or numeric vector of the same length asy. Usexandyto establish a nondefault spatial coordinate system. By default, if you do not specifyxandy, thenbwselectuses the intrinsic coordinate system in whichxis [1,size(BW,2)].

Example:x = [19.5 23.5];

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

Worldy-axis coordinates, specified as a numeric scalar or numeric vector of the same length asx. Usexandyto establish a nondefault spatial coordinate system. By default, if you do not specifyxandy, thenbwselectuses the intrinsic coordinate system in whichyis [1,size(BW,1)].

Example:y = [8.0 12.0];

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

x-coordinates of points in the world coordinate system, specified as a numeric scalar or numeric vector.

Example:x = [19.5 23.5];

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

y-coordinates of points in the world coordinate system, specified as a numeric scalar or numeric vector.

Example:y = [8.0 12.0];

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

Output Arguments

collapse all

Binary image containing objects that overlap the specified pixels, returned as a logical array.BW2contains the set of objects overlapping with any of the pixels specified byrandcorxiandyi.

If you do not specify an output argument, thenbwselectdisplays the output image in a new figure.

Linear indices of the pixels belonging to the selected objects, returned as a numeric vector.

More About

collapse all

Interactive Behavior

When you runbwselectwithout specifying pixel coordinates,bwselectenables you to select points interactively from an image in a figure window. Select points using these commands.

Interactive Behavior Description
Add points

Left-click points in the image.

Remove previous point

PressBackspaceor删除.

Add final point and complete selection

Right-click, double-click, or pressShiftand left-click simultaneously.

Complete selection without adding final point

PressReturn.

Extended Capabilities

Version History

Introduced before R2006a