# Multiple line fitting in binary image

조회 수: 2(최근 30일)
Jan Kubicek 2021년 9월 23일
Dear colleagues,
I would like to kindly ask you on the issue with multiple line fitting in MATLAB. I have a binary image with multiple skeletons, and I need to perform fitting of each line in this image by continous curve. I am able to do that for one line, see the code. Nevertheless, I am unable to do that for the all the lines at once automaticaly and plot the fitting results.
I use the image labeling: bwlabel() to recognize individual lines and for the fitting, I use the function smooth().
I would like to kindly ask you for the help with this task.
Thank you very much in advance. I use the following code:
image=i(:,:,2);
BW = logical(image);
BW1=bwskel(BW);
[skel_label N]=bwlabel(BW1);
figure()
imshow(BW1)
[r s]=size(skel_label);
for ii=1:r
for jj=1:s
if skel_label(ii,jj)==2
skel_label_mod(ii,jj)=1;
else
skel_label_mod(ii,jj)=0;
end
end
end
[coor1 coor2]=find(skel_label_mod);
yy1 = smooth(coor2,coor1,0.5,'loess');
figure()
imshow(i)
hold on
plot(coor2,yy1,'x')

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

### 답변(1개)

Harikrishnan Balachandran Nair 2021년 10월 19일
Hi,
I understand that you are trying to use the 'smooth' function on each of the connected components/curved lines that you got using the 'bwskel' function.
Using the 'bwlabel' fuction, each of the connected component in the corresponding image can be given a label number. This label can be used with the 'find' function to smooth the line with the corresponding label number. You can refer to the following code.
[skel_label N]=bwlabel(BW1);
figure()
imshow(i)
hold on;
for i=1:N
[coor1 coor2]=find(skel_label==i); % Finding all the co-ordinates for the corresponding component
yy1 = smooth(coor2,coor1,0.5,'loess');
plot(coor2,yy1,'x');
end
hold off;

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

### Community Treasure Hunt

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

Start Hunting!