Finish lines in the image

조회 수: 4 (최근 30일)
Mateusz Matysiak
Mateusz Matysiak 2019년 9월 16일
댓글: Matt J 2019년 9월 27일
Dear all,
I have an image like the one attached. I have it in binary format.
How do I complete the white lines so the first lines crosses x=0 point, and the remaining lines are finished until they cross each other?
This script should be flexible enough so the number of lines may change (more gaps) and they don't necessarily are lines. They may also be curves.
Here is another example where there are more gaps in data.
Thank you for your help!
  댓글 수: 5
Matt J
Matt J 2019년 9월 20일
Mateusz Matysiak's comment moved here:
The lines should look like below. Initially I was looking into creating multiple linear fit lines. Then, I create the complete lines based on the fits and cross points between the fits.
The picture below shows how it should look like. I finished the lines by hand. The script should do the same.
Matt J
Matt J 2019년 9월 20일
편집: Matt J 2019년 9월 20일
This script should be flexible enough so the number of lines may change (more gaps) and they don't necessarily are lines. They may also be curves.
You mentioned here that the pieces might be curved (not lines) and so naive line-fitting wouldn't work. Please show an example of this more complicated case and how you want the curves extended.

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

채택된 답변

Matt J
Matt J 2019년 9월 18일
편집: Matt J 2019년 9월 18일
Here is another method based on interpolation, and faster than dilating with large strels.
[m,n]=size(A);
[I,J]=find(bwskel(A));
IJ=sortrows([I,J],2);
[I,J]=deal(IJ(:,1),IJ(:,2));
Jw=(J(1):J(end)).';
Iw=round(interp1(J,I,Jw));
B=imdilate( accumarray([Iw,Jw],1,[m,n]) , strel('sphere',1));
imshow(B)
  댓글 수: 6
Stelios Fanourakis
Stelios Fanourakis 2019년 9월 20일
Still I struggle to get the correct results. Though I will stick to your first suggestion that works very good for me. Thanks Matt.
Matt J
Matt J 2019년 9월 20일
You are welcome, but please Accept-click an answer if you have found one that works for you.

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

추가 답변 (2개)

Matt J
Matt J 2019년 9월 17일
Perhaps as follows,
gapsize=36;
A=imcrop(rgb2gray(imread('image.png')));
B=(imdilate(A,strel('sphere',ceil(gapsize/2)))>0);
C=imdilate(bwskel(B),strel('sphere',1))|A;
imshow(C)
Capture.PNG
  댓글 수: 12
Stelios Fanourakis
Stelios Fanourakis 2019년 9월 27일
Matt how your code can be used in my image linking the first white pixel lines from the bottom of the image or the last white pixel lines (lines that look like dots) as you see the image from top to bottom.
I attach the image
Matt J
Matt J 2019년 9월 27일
I don't understand how the linking is supposed to work. I suspect, in any case, that it will require a very different method, since it is a very different kind of image. A new thread may be a good idea.

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


Image Analyst
Image Analyst 2019년 9월 18일
You might look to the "edge linking" link to the right for alternative methods. The method I like, which may be faster than dilation followed by skeletonization is to call bwmorph(bw, 'endpoints') and then use imline() to draw a line connecting endpoints closer than some distance that you specify.
  댓글 수: 1
Mateusz Matysiak
Mateusz Matysiak 2019년 9월 21일
Image Analyst,
Please explain the imline part. Please give an example.
Thank you

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

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by