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

1 Ansicht (letzte 30 Tage)
Ryan Bowman
Ryan Bowman am 1 Dez. 2018
Bearbeitet: Adam Danz am 1 Dez. 2018
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)

Akzeptierte Antwort

Adam Danz
Adam Danz am 1 Dez. 2018
Bearbeitet: Adam Danz am 1 Dez. 2018
"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)]')

Weitere Antworten (0)

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by