Slope Detection of line in a image
7 次查看(过去 30 天)
显示 更早的评论
Can I use this method of finding slope to this image
Ymin,Ymax,xmin and Xmax are coordinates of the line
slope=(Ymax-Ymin/Xmax-Xmin);
Because it is not a perfect straight line.So using this will be correct?
0 个评论
回答(2 个)
Image Analyst
2011-11-7
I wouldn't do it that way at all. That's just the slope between the endpoints. What you probably want is to use polyfit() to get the slope and offset so that you use all the points along the line. Write back if you can't figure out how to use polyfit.
3 个评论
Image Analyst
2011-11-7
I don't know what that means. Your coeff variable has the offset and the slope so I don't know what you're asking. However it looks like you're really struggling and could benefit from a full blown demo. See my answer below.
Image Analyst
2011-11-7
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 16;
xcoord = 0:42;
% Create a line with close 2 and offset 10;
ycoord = 2.0 * xcoord + 10;
subplot(3, 1, 1);
plot(xcoord, ycoord, 'rd-', 'LineWidth', 3);
grid on;
title('Perfect Y', 'FontSize', fontSize);
ylabel('Perfect Y', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1])
% Now add noise.
noisy_y = ycoord + 10*rand(1, length(xcoord));
subplot(3, 1, 2);
plot(xcoord, noisy_y, 'bd-', 'MarkerSize', 10);
grid on;
title('Noisy Y', 'FontSize', fontSize);
ylabel('Noisy Y', 'FontSize', fontSize);
% Now do the fit.
coeff = polyfit(xcoord, noisy_y,1)
fitted_y = polyval(coeff, xcoord);
subplot(3, 1, 3);
plot(xcoord, noisy_y, 'bd', 'MarkerSize', 10);
hold on;
plot(xcoord, fitted_y, 'r-', 'LineWidth', 3);
grid on;
title('Fitted Y', 'FontSize', fontSize);
ylabel('Fitted Y', 'FontSize', fontSize);
message = sprintf('The slope = %.3f\nThe intercept is %.3f',...
coeff(1), coeff(2));
uiwait(msgbox(message));
2 个评论
Image Analyst
2011-11-10
So just do it on the xcoords and ycoords that you have for each frame - you already know how to do that because you did it already for the first frame. Just do it like you did for the first frame.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!