www.gusucode.com > images 案例代码 matlab源码程序 > images/SelectObjectsInBinaryImageExample.m

    %% Select Objects in Binary Image
% Select objects in a binary image and create a new image containing only
% those objects.
%%
% Read binary image into the workspace.

% Copyright 2015 The MathWorks, Inc.

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');