Tangent line to the edge of binary image

4 views (last 30 days)
Tala
Tala on 25 Feb 2022
Edited: Matt J on 25 Feb 2022
Attached please see a binarized image of water droplets spraying out of a sprinkler.
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?
thanks you all :)

Accepted Answer

Matt J
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

More Answers (0)

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!