what does bwareaopen do?

I understand, bwareaopen(BW, P) means, the function removes pixels from BW matrix less than 'P' pixels and the default conn is 4 which means
conn=4 means
- X -
X 0 X
- X -
conn=8 means
X X X
X 0 X
X X X
but for example
A = 0 1 0 0 1 0
0 1 1 0 1 0
0 1 0 0 1 0
0 1 0 0 0 0
0 1 1 0 0 0
0 1 0 0 0 0
B=bwareaopen(A,4) gives
B = 0 1 0 0 0 0
0 1 1 0 0 0
0 1 0 0 0 0
0 1 0 0 0 0
0 1 1 0 0 0
0 1 0 0 0 0
that means A(1:3,5) which are ones are deleted -- pixels lesser than 4 are deleted.
then what is the significant of "conn" = 4?? even if the pixels are not connected with neighborhood 4, they are deleted. Why?

 Accepted Answer

You have 2 connected blobs. The one on the left is 8 pixels big (area of 8 pixels). The blob on the right is 3 pixels. When you called bwareaopen, it got rid of blobs less than 4 pixels. Since the blob with an area of 3 is less than 4, it was removed. Does that explain it? It has nothing to do with connectivity here because all your blobs are 4-connected. Now if you had an extra pixel diagonally connected to the blob on the left, like this:
A = 0 1 0 0 1 0
0 1 1 0 1 1
0 1 0 0 0 0
0 1 0 1 0 0
0 1 1 0 0 0
0 1 0 0 0 0
Now there are 8 eight connected blobs, but 3 blobs if you consider them as 4 connected. The pixel at row 4 column 4 is 8-connected to the blob on the left, but not 4 connected. It would be removed with
bwareaopen(A, 4, 4)
but not with
bwareaopen(A, 4, 8)
because in the second case it's connected while in the first case it's not connected.

5 Comments

Divya's "Answer" moved to a comment here because it's a reply to me and not an actual "Answer" to her original question:
Hey thanks for making it clear
But you are saying that when the pixel is not connected, it is removed ! But it is other way round know !!
BW2 = bwareaopen(BW, P) removes from a binary image all connected components (objects) that have fewer than P pixels..
Can you please make this too clear !
Yes it's removed. If you're telling it to consider your blobs as 4-connected, then the pixel at (4,4) is now it's own blob. It is not (north, south, east, west)-connected to any other blob. And since it has an area of 1, which is less that 4 (the parameter to bwareaopen), it is removed.
I say it's removed. The documentation says it's removed: "Remove small objects from binary image" But you say "But it is other way round know !!" Why do you think that pixels smaller than that parameter that the pixel is retained instead of removed?
Divya
Divya on 19 Apr 2014
Edited: Divya on 19 Apr 2014
Oh yeah.. !! Now I got it.. since the (4,4) pixel became single in conn=4,and no/. of pixels is less than 4, it got removed which will not happen in the case of conn=8 ...
Thank you so much for your answers ! very appreciative !
Divya asked (in an "Answer" that I moved here):
Hi, I got one more doubt! How does the matlab decides the blob? for example (as in your earlier comment) A =
0 1 0 0 1 0
0 1 1 0 1 1
0 1 0 0 0 0
0 1 0 1 0 0
0 1 1 0 0 0
0 1 0 0 0 0
(4,4) element can be considered in a blob where (4,4) is centered. But as you said earlier, (4,4) comes into a blob where (5,3) is centered.
Can you please illustrate how the blobs are considered?
If using 4-connected, then (4,4) is not connected to (5,3) since they touch only along the diagonal, not up/down/left/right. (4,4) would be its own separate blob in that case.
If 8-connected, then they're attached and part of the same blob.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!