how can I plot a graph over an image in Matlab?
    119 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    DARSHAN KUMAR BISWAS
 el 30 de Jun. de 2022
  
    
    
    
    
    Comentada: Vaughan Clarkson
 el 20 de Oct. de 2024
            

I want to plot the graph over the 1st image.
0 comentarios
Respuesta aceptada
  Kevin Holly
    
 el 30 de Jun. de 2022
        Load Example Image
exampleimage = imread('peppers.png');
Flip the image vertically (y-axis direction will be flipped vertically later)
exampleimage = flipud(exampleimage);
Display image
imshow(exampleimage)
Use hold on so more children can be added to the axes
hold on
Create scatter plot
x=1:20:300;
y=x;
scatter(x,y,'filled','w')
Change y-dir to normal (Note, y-dir is upside down when images are displayed by default)
set(gca,'YDir','normal') %gca stand for get current axes
7 comentarios
  Adam Danz
    
      
 el 5 de Jul. de 2022
				The question is continued here:
  Vaughan Clarkson
 el 20 de Oct. de 2024
				I have a slight variation on the original question which has bugged me for years.
What if (a) the image you're wanting to plot over the top of is larger than your screen and (b) you afterwards want to retrieve the modified pixel data in the original image size?
The problem I run into with Kevin's otherwise excellent solution is that, if the image is larger than the screen size, the imshow command will resize it to fit the screen.
Más respuestas (2)
  Adam Danz
    
      
 el 30 de Jun. de 2022
        Plot the image using image or imagesc or some other image function that allows you to specify the x and y values of the image.  That way you set the image coordinates to the data coordinates.  
Then just hold on and plot the data into the same axes.  
Note that image functions flip the y axis so you may need to flip it back to normal using set(gca, 'YDir','Normal') or flip your data when you plot it.  
If you have additional questions, share the code you've got so far and let us know specificially where you're stuck. 
2 comentarios
  Rik
      
      
 el 30 de Jun. de 2022
        You need to use the same axes. The easiest solution is to use hold, probably the line below will already do what you need:
hold(gca,'on')
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!










