Slope Detection of line in a image

7 次查看(过去 30 天)
Gova ReDDy
Gova ReDDy 2011-11-7
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?

回答(2 个)

Image Analyst
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 个评论
Gova ReDDy
Gova ReDDy 2011-11-7
How to offset to get the slope.
Image Analyst
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
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 个评论
Gova ReDDy
Gova ReDDy 2011-11-10
Thanks....
But Im trying to find slope of a line that is varying in each frame.
Using your example I assumed perfect line(the line which I took it as reference line from a frame) coordinates as (xcoord,ycoord)
and my noise line(line that is varying in each frame) coordinates as (xcoord1,ycoord1).
So how to fix this in your example
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));
Image Analyst
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 CenterFile Exchange 中查找有关 Image Segmentation and Analysis 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by