I have two binary image, A and B ( A and B are same size but have different object). There are many regions in each image. Now I want to find the neighbor of any regions in A. I use imdilate - dilation function in matlab. Because after dilation the regions of A will be increase so this may be connected with a region in B. I will add the region of B to A and continue to do it. I will stop when we can't add any region of B to A.
I don't know how to code this ? can you help me. thank you so much ? will it take a lot of time to calculate?

답변 (1개)

Image Analyst
Image Analyst 2014년 6월 26일

0 개 추천

So basically you want to keep growing A until it completely engulfs B. I'm not sure why/where this would be useful. But anyway, you can do this (pseudocode)
AorB = A; % Initialize
while true
if sum(A(:)) == sum(AorB(:))
break; % B is completely within A
end
A = imdilate(A, true(3)); % Grow A by one layer
AorB = A | B; % "OR" the growing A with the constant B image.
end
Basically keep growing until adding B to the growing A will not add any more pixels and the sizes are the same.

댓글 수: 1

Image Analyst
Image Analyst 2014년 6월 26일
편집: Image Analyst 2014년 6월 26일
Actually, you may be able to quit before A completely engulfs B, as long as all B are "connected" to A. Is that what you want? If that's true, label the image
[L, blobCount] = bwlabel(A);
and stop when blobCount = 1:
while true
A = imdilate(A, true(3)); % Grow A by one layer
AorB = A | B; % "OR" the growing A with the constant B image.
[L, blobCount] = bwlabel(AorB);
if blobCount == 1
break;
end
end
It will keep growing until all blobs in B are attached to A, then quit. It will not keep growing to engulf all blobs in B like the first code did. I think this is more like what you described.

댓글을 달려면 로그인하십시오.

질문:

2014년 6월 25일

편집:

2014년 6월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by