Plotting a graph on an image

7 visualizaciones (últimos 30 días)
Abdulrehman Zia
Abdulrehman Zia el 8 de Abr. de 2022
Comentada: Image Analyst el 9 de Abr. de 2022
I'm not sure why this code doesn't work. Whenever I run it the plot overrights the image even though hold is on. It seems to be because of the set statement but whenever I remove it the graph doesn't even show up. errors is a 1*21 column vector the image is 750*800. The plot needs to have tickmarks and labels Edit: I figured out the the image and the plot are both showing up but the scale is wrong so they never apppear in the same frame
[m,n]=size(images);
image(images)
colormap("gray")
hold on
plot([1:21],errors,'Color','red')
set(gca,'YLim',[0 max(errors)],'XLim',[0 numFrames],'YDir','normal', ...
'DataAspectRatio',[21/n,max(errors)/m,1])
hold off

Respuestas (1)

Image Analyst
Image Analyst el 8 de Abr. de 2022
This is definitely going to be a problem:
image(image)
image() is a built-in function. Do not use it as the name of your variable.
This works:
grayImage = imread('cameraman.tif');
[rows, columns, numberOfColorChannels] = size(grayImage);
imshow(grayImage, []);
colormap("gray");
hold on
errors = rows * rand(21, 1); % Whatever...
plot([1:21],errors, 'r-', 'LineWidth', 2); % You might think it's upside down. If so invert it and scale it.
% set(gca,'YLim',[0 max(errors)],'XLim',[0 numFrames],'YDir','normal', ...
% 'DataAspectRatio',[21/n,max(errors)/m,1])
hold off
  2 comentarios
Abdulrehman Zia
Abdulrehman Zia el 9 de Abr. de 2022
This doesn't work for me cause I need the plot to have tickmarks and labels
Image Analyst
Image Analyst el 9 de Abr. de 2022
So just add
axis('on', 'image');
Note that your image and your plot might have two different scales so you will have to decide which axes you want. It would probably be better to plot them in two separate axes rather than the plot on top of the image.

Iniciar sesión para comentar.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by