Identifying straight line & intersection with the curve from the binary image

I want to fit a blue line (curved or straight), detect a red line, and then find the slope of the light green line that is tangent to the blue line at the intersection of the two lines.
By detecting the first row in each column with the value 1, I could detect blue line.
Also, fitting blue curvature from this data would be no problem.
In the case of a straight line section, it seems to be possible to first find the row with a value of 1 for each column, average it, and then draw a straight line to the value on the leftmost side.
However, in this case, it seems that I have to manually determine the location of the pixel corresponding to the straight line section(otherwise, even curved surfaces will be recognized).
Any suggestion would be very helpful.
Thank you.

 채택된 답변

Image Analyst
Image Analyst 2023년 11월 23일
The best solution is if you can put your part into some kind of jig so that everything is in a fixed, known position. Then you can just use a fixed mask to erase everything you don't want.
Another way might be to scan the image row by row using find() and find out where that large rectangular gap is. Then just erase 3 or 4 columns just to the outside of the rectangular gap.
Another option would be to scan the image getting the top rows and then try to find the change point using findchangepts.
Another option would be to just fit everything, spike and all, then find the residuals between your fit and the actual data and say that if the residual (difference) is too much, then delete those points and train your polynomial again.

댓글 수: 1

Unfortunately, the 'best solution' is unlikely to be available.
I'm trying the rest of the methods.
Thanks for the answer.

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

추가 답변 (1개)

Matt J
Matt J 2023년 11월 23일
편집: Matt J 2023년 11월 23일
load BWimage
C=bwareafilt(BW&~imopen(BW,ones(1,8)),1);
[I,J]=find(C);
x=mean(J); y=max(I); %intersection coordinates
imshow(BW); hold on
scatter(x,y,'r','filled'); hold off

댓글 수: 3

DW
DW 2023년 11월 28일
편집: DW 2023년 11월 28일
It actually works pretty well for most of the images I'm interested in.
There are some areas where it doesn't work as well, but I think it can be adjusted somewhat.
I'm trying both Image Analyst's method and yours.
I've already selected Image Analyst's answer, so I apologize for not being able to select yours.
I really appreciate your answer.
@DW You can click the Vote icon on his answer. Clicking Vote also awards reputation points.

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

카테고리

도움말 센터File Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

질문:

DW
2023년 11월 23일

댓글:

DW
2023년 11월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by