Select points on plot and calculate slope
이전 댓글 표시
I have been trying to select two points on an image and then calculate the slope based on the location of those two points. I have been using getpts but keeping "Error using getpts line 174 Interruption during mouse point selection"
I have tried a few versions of the code:
In version three I get an output which I don't fully understand
m =
-0.7083 0
-0.7500 0
%Version 1
X=imread('dog.jpg');
figure,imshow(X)
[x,y] = getpts;
%Version 2
read and display image to add markers
X=imread('dog.jpg');
figure,imshow(X)
[x1,y1] = getpts(get(imshow(X),'Parent'));
[x2,y2] = getpts(get(imshow(X),'Parent'));
hold on
p1 = [x1,y1];
p2 = [y1,y2];
%Version 3
X=imread('dog.jpg');
figure,imshow(X)
[x1,y1] = ginput(1);
hold on; % Prevent image from being blown away.
plot(x1,y1,'r+', 'MarkerSize', 25);
[x2,y2] = ginput(2);
hold on; % Prevent image from being blown away.
plot(x2,y2,'r+', 'MarkerSize', 25);
m = (y2-y1)/(x2-x1)
댓글 수: 1
KALYAN ACHARJYA
2019년 6월 5일
Is this your question?
- Select any two points on the image
- Draw Line between those selected two points
- Calculate the slope of that line
Clarify?
답변 (1개)
KALYAN ACHARJYA
2019년 6월 5일
im=imread('1.png');
[rows colm]=size(im);
point1=[randi(rows),randi(colm)];
point2=[randi(rows),randi(colm)];
imshow(im);
hold on;
line(point1,point2,'linewidth',2);
slope=(point2(2)-point1(2))/(point2(1)-point1(1));
fprintf('The slope is %f',slope);
카테고리
도움말 센터 및 File Exchange에서 Image Arithmetic에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!