Superimposing a Quiver plot over an Image

34 views (last 30 days)
Hello, I have an Quiver plot I want to superimpose over a color mapped image. i.e. The image was developed with the use of the ind2rgb so it is a nxmx3 matrix. Any suggestions?? Thanks in advance!
  2 Comments
Gautam Mohan
Gautam Mohan on 2 Jun 2016
Hi,
A technique you could use would be to plot the image on a fixed axis, and then plot the quiver on the same axis afterwards, ensuring that hold is on (using the command 'hold on') to plot the quiver on top of the image.
Here is an example:
(I have taken an arbitrary quiver plot from a doc example and plotted it over a default image in MATLAB. This example should generalize to whatever quiver plot and image data is required.)
im = imread('autumn.tif');
[x,y] = meshgrid(-2:.2:2,-1:.15:1);
z = x .* exp(-x.^2 - y.^2); [px,py] = gradient(z,.2,.15);
quiver(x,y,px,py); axis image %plot the quiver to see the dimensions of the plot
hax = gca; %get the axis handle
image(hax.XLim,hax.YLim,im); %plot the image within the axis limits
hold on; %enable plotting overwrite
quiver(x,y,px,py) %plot the quiver on top of the image (same axis limits)
Note that if you already know the axis limits beforehand, you can set them and omit the first quiver plot. The only reason I plotted quiver first was to obtain the limits (which can sometimes be slightly greater than normal to account for the space the arrows take up).
Hope this helps!
Marco A. Acevedo Z.
Marco A. Acevedo Z. on 6 Apr 2021
First, use imshow(img) and then hold on and use quiver(X, Y, U, V). Remember to set axis(equal). The xlim are automatically set afaik. Cheers,

Sign in to comment.

Answers (0)

Categories

Find more on Vector Fields in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!