MATLAB: What does bwareaopen do

bwareaopendigital image processingimage analysisimage processingImage Processing Toolbox

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?

Best 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.