# Find distance between foregrounds of two binary images

2 views (last 30 days)
Simon Schiele on 16 Sep 2020
Commented: Simon Schiele on 21 Sep 2020
I have an image that looks like this:
I found the colored lines using hough transform.
I would now like to measure the width of the corresponding thick lines in the image.
I can draw a second image based on the Hough lines (the sizes of the images are equal, looks different here because they are screenshots):
So my basic idea is using something similar to bwdist to calculate the distance between all points in image one to those in image 2.
Any ideas?

KALYAN ACHARJYA on 16 Sep 2020
Steps:
1.As you already know the indices of all three lines from the 2nd image. If not following is the way
[r2 c2]=find(image2==1);
2. Next force the all pixel with zero of r2 and c2 in 1st image. the find the indices the all white pixel in first image
[r1 c1]=find(image1==1);
3. Calculate the distances between all sets of [r1,c1] and [r2,c2]. Tou can proceed the first index pair of (r2,c2) with all indices pair in image 1, which are [r1,c1]. Next another index pair of (r2,c2) with all indices pair in image1..so on
At last you will get the distances between all three lines and all other white pixels in the image.
Hope it helps!
Kalyan

#### 1 Comment

Simon Schiele on 21 Sep 2020
Thanks for your comment! This seemed a bit expensive to me, so I tried a different approach. I treat each line separateley. I first invert the line image and calculate the distance from this inverted image to the background using bwdist. This gives the distance of each line to any point in the image. Then I use my original binary image as mask to remove all distances from line to background. The histogram can then be used to find the width of the lines.