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

1 visualizzazione (ultimi 30 giorni)
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)

Risposta accettata

Adam Danz
Adam Danz il 1 Dic 2018
Modificato: Adam Danz il 1 Dic 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)]')

Più risposte (0)

Categorie

Scopri di più su Images in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by