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

    %% Filter Binary Image by Size of Objects
% 
%%
% Read image.

% Copyright 2015 The MathWorks, Inc.

BW = imread('text.png');
%%
% Filter image, retaining only the 5 objects with the largest areas.
BW2 = bwareafilt(BW,5);
%%
% Display the original image and the filtered image side by side.
imshowpair(BW,BW2,'montage')