2.0

2.0 | 1 rating Rate this file 14 downloads (last 30 days) File Size: 870 Bytes File ID: #15596

Retaining the largest blob in an image

by Ani

 

16 Jul 2007 (Updated 16 Jul 2007)

No BSD License  

'bwlargestblob' reads in a 2-d binary image and outputs a binary image, retaining only the largest b

Download Now | Watch this File

File Information
Description

'bwlargestblob' reads in a 2-d binary image and outputs a binary image, retaining only the largest blob.

Usage: [outim] = bwlargestblob(im,connectivity)

im - 2-d binary image
conenctivity - Accepts 4/8 connectivity
outim - Output binary image (with 1s and 0s)

Example:

im = imread('text.png');
outim = bwlargestblob(im,8);
figure;
subplot(1,2,1); imshow(im);
subplot(1,2,2); imshow(255*outim);

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.0.1 (R14SP1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
16 Jul 2007 D S

This function may work as advertised (I have not tested it), but it needs to be improved. The help should include a "see also" line that points users to the help for BWLABEL and REGIONPROPS. The image processing toolbox help discusses this problem and provides an example along these lines:

%bw is some logical (black and white) image
[Lbw] = bwlabel(bw);
%calculate area for each labeled object
stats = regionprops(Lbw,'Area');
[largest_area,la_label] = max([stats.Area]);

16 Jul 2007 D S

Apologies. I missed the point a little when I wrote my first comment. It looks like you want the original image with everything but the largest blob blanked out. In that case, you need more than the snippet I wrote there to get the job done. The example for this FX submission shows another possible solution to this problem:
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=13896

07 Mar 2008 manoj rao

i am trying traffic measurement and want to select only the road from the pic.how can i use your function.its an rgb image

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
morphology Ani 22 Oct 2008 09:19:29
segmentation Ani 22 Oct 2008 09:19:29
largest blob Ani 22 Oct 2008 09:19:29
image blob Ani 22 Oct 2008 09:19:29
largest area Ani 22 Oct 2008 09:19:29

Contact us at files@mathworks.com