How to connect two objects based on least distance between them?

I have a binary image containing two separate objects...I want to connect them such that they are connected on basis where the distance between them is the least?

 採用された回答

Image Analyst
Image Analyst 2015 年 7 月 1 日

1 投票

Call bwboundaries. Then have some for loops where you check all the boundary coordinates to see which distance is least. Then you can use imline() to burn a connecting line into the image, like in the attached demo.

7 件のコメント

peyush
peyush 2015 年 7 月 1 日
How to check for the boundary coordinates to find least distance?...please can you help
Image Analyst
Image Analyst 2015 年 7 月 1 日
See similar demo where I find the two points that are farthest apart. If you still can't figure it out, write back.
peyush
peyush 2015 年 7 月 2 日
編集済み: peyush 2015 年 7 月 2 日
thanks for your reply...i have a query....what do the statement: maxDistance = -inf; mean?...thanks for your time
Image Analyst
Image Analyst 2015 年 7 月 2 日
That's initializing the maxDistance to minus infinity. Since you're checking each distance against the running current max value, what value are you going to check the very first distance against? You wouldn't pick a billion because no line in your image is a billion pixels long and you'd never get the correct max length if that were the first value. So you can pick any length from minus infinity to zero. The very first distance, no matter what it is, is guaranteed to be longer than that and so it will update the max length.
peyush
peyush 2015 年 7 月 2 日
編集済み: peyush 2015 年 7 月 2 日
thanks for explaining... i am using the script for finding the nearest distance between two objects ...but i am getting the following error implementing it:
*Error using griddedInterpolant The coordinates of the input points must be finite values; Inf and NaN are not permitted.
Error in interp1 (line 169) F = griddedInterpolant(X,V(:,1),method);
Error in improfile (line 214) profi = interp1(cdist,pCoordinates,0:(max(cdist)/(N-1)):max(cdist));*
please help...
peyush
peyush 2015 年 7 月 3 日
Sir please help me...
Image Analyst
Image Analyst 2015 年 7 月 3 日
Your code does not look like you adapted it at all? Did you?

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2015 年 7 月 3 日

0 投票

peyush, your code didn't even seem to attempt to modify my code at all. It looks like I need to do it for you. See the attached demo which makes the connection.

1 件のコメント

peyush
peyush 2015 年 7 月 4 日
thank-you so much for helping me out :-)

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

質問済み:

2015 年 7 月 1 日

コメント済み:

2015 年 7 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by