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

2 次查看(过去 30 天)
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 中查找有关 Visual Exploration 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by