Centerline detection from the binary image.

조회 수: 6 (최근 30일)
DW
DW 2023년 11월 22일
편집: DW 2023년 11월 23일
I have multiple images taken of the same object.
However, as in the example below, not all objects are located in the center.
I want to identify central axis of the object(based on the standard of ensuring that the length of the light blue arrows is the same as shown in the image below) and indicate the center line and crop the image based on this.
I think I can do the crop itself as long as I know the index of the center line.
It would be very helpful if you could tell me where to start.
Thank you!
#1 Result of Angelo Yeo's code (cropped image)

채택된 답변

Image Analyst
Image Analyst 2023년 11월 22일
What I'd do is to find the rows where you have two blobs, instead of 0 or 1. Then for those, log the left edge and the right edge. Then take the average of them after you've scanned every row. Let me know if you can't figure it out.
  댓글 수: 1
DW
DW 2023년 11월 23일
편집: DW 2023년 11월 23일
Hello,
I'll try your solution.
Thank you for your reply :)

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

추가 답변 (1개)

Angelo Yeo
Angelo Yeo 2023년 11월 22일
편집: Angelo Yeo 2023년 11월 22일
I didn't detect rectangulars, but would this work for you?
img_orig = imread('image.png');
img = imbinarize(img_orig);
[~,c] = find(img(:,:,1) == 1);
figure;
imshow(img_orig); hold on;
line(ones(1,2) * mean(c), [0, size(img,1)],'color','r', 'linewidth',2)
  댓글 수: 1
DW
DW 2023년 11월 22일
Thank you for your kind reply!
I tried your code, it works well for that butterfly image.
However, when I tried with other image with similar structure, the red line wasn't at the center of that rectangular(I attached picture).
It seems your code detect center line based on the average position of points with a value of 1.
Therefore, when the left and right sides have similar distributions of 1 values, the center position is estimated well, but when the distribution of 1s (white) is concentrated on one side, it does not seem to fit well.

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by