How to draw lines in between points that the user provides?

조회 수: 3 (최근 30일)
Ryan Bowman
Ryan Bowman 2018년 12월 1일
편집: Adam Danz 2018년 12월 1일
I have a picture uploaded to matlab where I have the user pick four points, then I shall have red lines that are made in between those points that should make a square (or somehat close to a square). I also what to convert the image to grayscale using the 'jet' colormap. This is my code so far:
The x = ... and y = ... is clearly wrong as it makes a seperate figure with lines and the lines are not on the picture.
clc;
close all;
clear;
%%
davis = imread('DavisHall.jpg');
figure(1), imagesc(davis), axis image
PickCorners = ginput(4)
x = [PickCorners(:,1)];
y = [PickCorners(:,2)];
plot(x',y')
hold on
davisgray = rgb2gray(davis)

채택된 답변

Adam Danz
Adam Danz 2018년 12월 1일
편집: Adam Danz 2018년 12월 1일
"The x = ... and y = ... is clearly wrong as it makes a seperate figure with lines and the lines are not on the picture. "
You need to specify the axis in your call to plot(). After calling imagesc() get the handle to you axis using gca()
h = gca;
hold(h, 'on')
plot(h, x', y')
If you want to draw a square, you'll need to add the first coordinate on to the end of each x and y vector to complete the square.
plot(h, [x;x(1)]', [y;y(1)]')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by