Tangent line to the edge of binary image
4 views (last 30 days)
Show older comments
Attached please see a binarized image of water droplets spraying out of a sprinkler.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/906900/image.jpeg)
I am trying to define a the angle between a normal line and (1) the right edge of the blob (dotted line) and left edge of the blob (dashed line). A solution that comes mind is to get rid of smaller blobs and is to extract the (x,y) values of the edges and fit a curve to each section. Can anyone suggest a better solution to me?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/906905/image.jpeg)
thanks you all :)
0 Comments
Accepted Answer
Matt J
on 25 Feb 2022
Edited: Matt J
on 25 Feb 2022
A solution that comes mind is to get rid of smaller blobs and is to extract the (x,y) values of the edges and fit a curve to each section.
Sounds good to me.
load Image
BW0=BW;
BW=bwperim( bwconvhull(bwareaopen(BW,100)) );
[I,J]=find(BW);
[~,p]=min(I);
[~,l]=min(J);
[~,r]=max(J);
Ip=I(p); Jp=J(p);
Il=I(l); Jl=J(l);
Ir=I(r); Jr=J(r);
Ic=min(Il,Ir);
Im=round((Ip+Ic)/2);
BW(Ic:end,:)=0;
BW(1:Im,:)=0;
reg=regionprops(BW,'PixelList');
for i=1:2
x = reg(i).PixelList(:,1);
y = reg(i).PixelList(:,2);
reg(i).p=polyfit(x,y,1);
end
imshow(BW0,[]);
hold on
x1=1:Jp;
y1=polyval(reg(1).p,x1);
x2=Jp:size(BW,2);
y2=polyval(reg(2).p,x2);
plot(x1,y1,'rx')
plot(x2,y2,'rx')
hold off
0 Comments
More Answers (0)
See Also
Categories
Find more on Image Processing and Computer Vision in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!