center to center distance between objects: Need advise

2 ビュー (過去 30 日間)
Abdul Hannan Qureshi
Abdul Hannan Qureshi 2022 年 4 月 30 日
編集済み: Abdul Hannan Qureshi 2022 年 5 月 10 日
I am trying to calculate center to center distance between lines, i.e., between intersection points. I am working on this image
I want to achieve this
However, following steps I have assumed like
  1. detect centerlines in the image.
  2. detect intersection points.
  3. calculate horizantal distances between intersecting points.
  4. calculate vertical distances between intersecting points.
I am a bit confused about functions to be applied here. If anyone can advice which fucntions will be helpful to be to achieve above outcome OR if there is some better methodlogy to achieve above shared outcome. Kindly advise.
  2 件のコメント
Alberto Cuadra Lara
Alberto Cuadra Lara 2022 年 4 月 30 日
編集済み: Alberto Cuadra Lara 2022 年 4 月 30 日
Hi Abdul,
I haven't done any image processing for a long time, but maybe these comments can help.
  1. Remove image noise (imguidedfilter).
  2. Black and white conversion (rgb2gray).
  3. Convert to binary (imbinarize).
  4. Remove all elements smaller than a certain number of pixels (bwareaopen).
  5. Obtain the center of each line (regionprops).
If you know the pixel relation you can obtain also the values in micrometer, for example.
Best,
Alberto
Abdul Hannan Qureshi
Abdul Hannan Qureshi 2022 年 4 月 30 日
thanks, I will try this sequence.

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

採用された回答

Image Analyst
Image Analyst 2022 年 4 月 30 日
Another way is to get two images, one of all the vertical lines and one of all the horizontal lines. Use imopen() with the proper structuring element - either a vertical or horizontal rectangle.
Then threshold and get the centerlines with bwskel()
Then get a list of (x,y) for each line.
Then compare every vertical line with every horizontal line to find the distance that is min. This is where they cross. You can either use pdist2() or use a loop with sqrt(). This will give you the (x,y) intersection point for every line.
After that it's just some looping and bookkeeping to get the distances between adjacent points.
Again, if you can't figure it out, let me know.
  7 件のコメント
Image Analyst
Image Analyst 2022 年 5 月 7 日
Why not? Is it still a problem? Can you run my code without error? If so, then attach your code.
Abdul Hannan Qureshi
Abdul Hannan Qureshi 2022 年 5 月 7 日
編集済み: Abdul Hannan Qureshi 2022 年 5 月 10 日
@Image Analyst, the code is running perfect. Thank you for assistance.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2022 年 4 月 30 日
What I'd do is what I actually do in a very similar situation, though I'm looking for 5 points on the perimeter not 5. Here is the algorithm I think you can use
  1. binarize the image to find dark rectangles mask = imbinarize();
  2. call mask = bwareafilt(mask, [smallest, largest]) to get rid of small blobs and the super large one touching the border and get ONLY the valid squares.
  3. call imfill(mask, 'holes');
  4. Find centroid with props = regionprops(mask, 'Centroid', 'Image')
  5. Loop over all blobs and for each blob, props(k).Image, find boundaries with bwtraceboundary. Start on the left middle edge so you have a known starting point.
  6. Find distance of all boundary points to that blob's centroid and plot them. distances = sqrt((xCentroid-x)^2+(yCentroid2-y)^2)
  7. Find peaks with findpeaks(distances, .....). Specify the MinPeakDistance as half the approximate width of the square. If there are more than 4 peaks found, take the 4 with the highest prominence value. This gives you the index of the corners in the boundary coordinates. You'll have 1 is the upper left, 2 = upper right, 3 = lower right, and 4 = lower left.
  8. Compute distances like d12 = sqrt((x2-x1)^2+(y2-y1)^2), and similar for d23, d34, and d41. Stored the distances for each blob.
If you can't code it up from the pseudocode I've given so far, then let me know and I'll finish it.
  1 件のコメント
Abdul Hannan Qureshi
Abdul Hannan Qureshi 2022 年 4 月 30 日
編集済み: Abdul Hannan Qureshi 2022 年 5 月 6 日
Thank you for this.

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

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by