如何在图像中获得曲线的功能?

时间:2017-03-30 18:40:47

标签: matlab function 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);

测试图像是下一条曲线

enter image description here

1 个答案:

答案 0 :(得分:1)

弧长的公式为

  s = Integral Sqrt[1 + (dy/dx)^2] dx,

其中两个x端点的积分限制。对于大多数曲线来说,这不是很易处理,所以你不得不求助于加入小的线性碎片。