Reputation: 626
I need get function of the curve, because i need to calculate to get lenght curve. Firstly I try to get the function from curve
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
grayImage = grayImage(:, :, 2); % Take green channel.
end
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
binaryImage = grayImage < 100;
subplot(2, 2, 2);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);
axis on;
[rows, columns] = find(binaryImage);
coefficients = polyfit(columns, rows, 3);
fittedX = linspace(min(columns), max(columns), 500);
fittedY = polyval(coefficients, fittedX);
subplot(2,2,3:4);
plot(fittedX, fittedY, 'b-', 'linewidth', 4);
grid on;
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
hold on;
plot(columns, rows, 'r+', 'LineWidth', 2, 'MarkerSize', 10);
the test image is next curve
Upvotes: 1
Views: 167
Reputation: 6404
The formula for arc length (s) is
s = Integral Sqrt[1 + (dy/dx)^2] dx,
where the limits of the integral at the two x end points. This isn't very tractable for most curves, so you have to resort to adding up small linear pieces.
Upvotes: 1