Slope Detection of line in a image
조회 수: 2 (최근 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에서 Basic Display에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!