user2958673
user2958673

Reputation: 11

How do i draw an arc/spline on an image and get the length?

I can draw a line using points, but i am not sure how to draw a curve.

This was my code:

clc;
clear all;
I = imread('im6f.jpg');
figure,imshow(I);

[x,y] = ginput(2);

Then I used the distance formula to get the length.

How can i do a curve?

Upvotes: 0

Views: 1593

Answers (1)

s.bandara
s.bandara

Reputation: 5664

How about using interp1 for interpolating a spline? Let's say fold = 10 is the approximate increase in resolution you want. Then, [x, y] = ginput() without a specific upper limit of points. The number of points the user specified is n = length(x). Then,

t = 1 : (1/fold) : n;
xi = interp1(1 : n, x, t, 'spline');
yi = interp1(1 : n, y, t, 'spline');
plot(xi, yi, 'linewidth', 3);

gives you the following, where the red blobs mark the points where I clicked. You have to press Enter to stop collecting coordinates.

enter image description here

xi and yi are fold-fold resampled coordinates of x and y using 'spline' as the interpolation method. You could have a look at this for other options.

dx = xi(1 : end-1) - xi(2 : end);
dy = yi(1 : end-1) - yi(2 : end);
d = sum(sqrt(dx.^2 + dy.^2));

d is roughly the length of that spline, calculated as the sum of the length of all edges. In the case shown above, d = 118.97.

Upvotes: 2

Related Questions