Drawing an arrow on top of an image - MATLAB - matlab

I'm trying to draw an arrow on top of an image in MATLAB, between two pixels: [x0,y0] and [x1,y1].
I tried to use annotation function. The problem is that the function takes as an input x,y values which represent coordinates on the figure, instead of on the image itself.
Does anyone knows how can I draw an arrow between two pixels in an image?
Example
imshow(imread('peppers.png'));hold on;
I would like to generate a blue arrow from pixel (1,1) to pixel(200,200), so it should look something like this (only in blue instead of black):
Thanks!

you could simply use the quiver-function:
figure;
imshow(imread('peppers.png'));hold on;
quiver(0,0,200,200,0)

Related

How can I add the color in the gray image

I have a gray image. I would like to add two markers to the image. In which, a marker is blue mark withi color code (0000FF) and other marker is red mark FF0000. Could you help me to add this mark in the gray image using MATLAB? Note that, each marker has shape is rectangular shape. Thanks
This is my input and my expected output
The original image can be download at here
Use the rectangle function to apply the mask. Now for saving the figure in desired size, you could set the PaperPositionMode to manual and get the desired image size. The code below also shows different ways to save the figure in different formats.
[A, cmap1] = imread('11.bmp');
imshow(A,cmap1);
hold on;
rectangle('Position',[45,45,20,10],'EdgeColor','r','FaceColor','r');
hold on;
rectangle('Position',[50,80,30,10],'EdgeColor','b','FaceColor','b');
hold off;
f = getframe();
imwrite(f.cdata,'myfigure.bmp');
Here is the resulting image:
Use the insertShape function in the Computer Vision System Toolbox.

Matlab: Put an image ON TOP of a plot, after the data has been plotted

I have searched the internet for a solution to the question above but have had no luck up to now. I have been producing a number of 2D plots where the origin of (0,0 point) is represented by an image. I have made these by plotting the data on an image, where the image is all white apart from the desired symbol at the center point (so I can reshape it as needed). I then move the axis so they cross at the center point. This all works fine, but I now have to create a number of plots using ‘fill’ to place two shaded areas on the plot that overlap in the center. This causes the symbol to be difficult to see even using ‘alpha’.
I therefore have two options to get the desired effect, both requiring me to put an image on top of the figure after the data is plotted. These options are:
1) I place the image on top of the plot and apply alpha to it (May not look very good as it will mute the plot).
2) The better option would be to crop the image around the symbol and then position it on top of the plot so the image center is at the origin (I have no idea how to position the image this way).
Both methods need the image to be placed on top of the plot after the data is plotted. I have tried 'hold on' and calling 'figure(imagesc(Image))' neither work. I have Matlab 2012b but no toolboxes (so cannot use subimage etc.)
Thanks for any help you can give
You can set the transparency of individual pixels of an image using the 'AlphaData' option. So, you can plot the overlay as follows:
% plot your data normally
...
hold on
% assuming the overlay is a 11x11 image
image(-5:5,-5:5,image_matrix,'AlphaData',alpha_matrix);
image_matrix would obviously be the matrix with your image data stored in it, while alpha_matrix would be a matrix of the same size as image_matrix. Every pixel you want to show would have a value of 1, every pixel you want to hide (the white pixels) would be 0.

How to add an image thumbnail as(or beside) a plot marker in MATLAB?

I am running Isomap Dimensionality reduction in MATLAB on a series of images. I want to plot the image's thumbnail beside the point on the manifold corresponding to it.
I am currently using 2 differnt isomaps http://isomap.stanford.edu/ and http://robotics.cs.brown.edu/projects/stisomap/ .
The imagesc function can take arguments which dictate where the image is drawn, so I would use this. Here's an example of imagesc being drawn on top of a plot:
% Draw plot
vals=rand(2,100);
plot(vals(1,:),vals(2,:),'x');
hold on;
% Draw image
im=imread('moon.tif');
xs=linspace(0.1, 0.2, size(im, 2) );
ys=linspace(0.1, 0.2, size(im, 1) );
colormap gray;
imagesc(xs,ys,im)
Which looks like this:
Note the first two arguments to imagesc which define the range over which the image is drawn. Obviously you'll want to change the arguments to linspace, which will define the position and size of the image, and you'll need to take account for the aspect ratio if the image isn't square, but hopefully this will get you along the right lines.

Matlab - reverse value of axis in plot [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How do I edit the axes of an image in MATLAB to reverse the direction?
The colour image is plotted using the image function based on some information obtained using imread function and for the white and blue image basically I am selecting the coordinates of the heat point(red and blue and their variations basically) from the map and then displaying them using plot function. The problem is that the plotted values are reversed on the Y axis and I can't figure out how to reverse the Y axis of the plot in order to obtain the same correlation between the images.
Could you please explain me how to solve this problem?
By default, matlab draws graphs with (0,0) at the bottom left corner. However, it draw images with (0,0) in the top-left corner.
You can change the image axes to standard bottom-left origin by using the command
axis xy;
Remember to make sure that your image is the currently selected figure.
Use rot90() to rotate the matrix, or a combination or fliplr() (flips matrix, left and right) and flipud() (flips matrix up and down) that produced the heat map image.
If you are plotting an image and you don't want to see the axis tic marks you can turn them off with
axis off
if you are interested in changing the direction of either the x-axis and/or y-axis in an axes handle-object, you can use the set function as follows
set(axesHandle,'XDir','rev','YDir','rev')
where you use XDir or YDir (or both) based on the axis you want reversed.

Markers and the imagesc() function in matlab

How do you create a marker on a 2D image that is plotted using imagesc()? Is it even possible?
You simply want to draw something over your image? Then you can just use hold on.
For example, this will draw a circle at the 10,10 pixel of the image.
imagesc(magic(24));
hold on
scatter(10,10);