Slope Detection of line in a image
8 ビュー (過去 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!