What are the Coordinate Axes alignment in plot generated by quiver - matlab

I am using quiver to plot optical flow over my image using this answer.
Following is taken from matlab quiver documentation page
A quiver plot displays velocity vectors as arrows with components
(u,v) at the points (x,y).
For example, the first vector is defined by
components u(1),v(1) and is displayed at the point x(1),y(1).
We know that while reading an image the index(1,1) is at top left.
Now where does quiver assumes it's origin and in which direction it assumes the alignment of axes while generating the plot.

By default the x axis values increase to the right and the y axis increase towards the top.
However imshow which is used in the linked answer reverses the y axis direction, similar to axis('image'). This is because image data is generally stored with the top left of the image appearing first in the data.
The directions can be checked with:
get(gca,'ydir')
get(gca,'xdir')
if hold is on quiver will plot using this reversed y direction so the origin is in the top left. (assuming the lowest value for the axis is 0)
If hold is not on or the directions are not reversed the origin will be at the bottom left and quiver will use with the default axis directions. (again assuming values>=0)

Related

MATLAB Shift the origin (0,0) of the pixels in my image

As an input of my code, I need to have some positions on my picture: the positions are in pixels and the origin (0,0) is in the CORNER top left of my picture
The problem is that when I run my code which maps the positions on my picture, the origin shifts to the bottom left :
So my question is : how could I also shift my input (positions of my picture1) so that it is relevant with the code process?
Thank you for your help,
Aude
Adding an answer with a bit detail:
In computers, image processing etc it is the norm to have the (0,0) pixel in the top left corner. However, it is understandable that when you have x,y data, you'd want to plot it together with the image. Here some solutions:
imshow(image);
axis xy; % This line sets up the axis in a standard coordinate system
you can revert it with axis ij
Often, this is not enough. As imshow assumes that each pixel is in integer index position, and you may not have that. Maybe your data is in milimeters, or in any other arbitrary units. A solution to that is using imagesc
imagesc(img);
is equivalent to imashow(img);axis xy. Additionally, you can choose arbitrary matrices for pixel locations as imagesc(x,y,img);
Finally, you can flipud your data for plotting, but I suggest you do that inline with the plot, so you dont modify the data itself.
imshow(flipud(img))
With images you reverse the Y axis:
set(ax,'YDir','reverse');
That would depend on your code. Maybe you can do it on-the-fly so you'll get the desired output right away.
If not just flip the output. You could use flipud for that.
https://de.mathworks.com/help/matlab/ref/flipud.html

Change 3D view in matlab

I would like to change the view of a 3D plot in matlab such that the y-axis points upward and the z-axis points to left. For example, consider the following plot:
Here the x-axis points forward, the y-axis points to the right and the z-axis points upward.
I would like to have the y-axis points upward and the z-axis points to the left instead. I tried to rotate the plot (using the figure window toolbar rotate button) but I could not get it to work. (It should just be a simple 90 degrees rotation about the x-axis)
Code to generate the plot:
membrane
view(100,50)
xlabel('x-axis');
ylabel('y-axis');
zlabel('z-axis');
grid on
Try using view. I don't have MATLAB available so I can't test it, but I think it can do what you want.
Example from the documentation:
Set the view along the y-axis, with the x-axis extending horizontally
and the z-axis extending vertically in the figure.
view([0 0]);
EDIT:
Try using three inputs to the view function. I can't experiment myself, but you should be able to do it if you choose the right values here.
From documentation:
view([x,y,z]) sets the view direction to the Cartesian coordinates x,
y, and z. The magnitude of (x,y,z) is ignored.
EDIT 2:
Check out camroll. I think camroll(90) (possibly in combination with view) will work.
From documentation:
camroll(dtheta) rotates the camera around the camera viewing axis by
the amounts specified in dtheta (in degrees). The viewing axis is the
line passing through the camera position and the camera target.
This was posted a while ago, but in case someone else is looking for ways to set y-axis as the vertical one here is a possible fix.
Manually: In the command window type cameratoolbar('show') which will open an interactive toolbar in your plot from which you could change the view. One of the options is to set a principle axis to x, y, or z.
Or in you script you could use cameratoolbar('SetCoordSys',coordsys) command which sets the principal axis of the camera motion. coordsys can be: x, y, z, or none.
http://uk.mathworks.com/help/matlab/ref/cameratoolbar.html

Matlab: mirror results along xaxis

I can't seem to find any documentation explaining how to mirror my matlab results.
ie I have this:
and I want my results to be upside down....
using set(gca, 'XDir', 'reverse') and set(gca, 'XDir', 'reverse'Y do not work for me ( I am using figue and quiver to plot)
For display purposes, you can move the origin to the upper left corner via:
axis ij
By default when plotting it uses axis xy. Excerpt from axis documentation:
axis IJ puts MATLAB into its "matrix" axes mode. The coordinate system origin is at the upper left corner. The i axis is vertical and is numbered from top to bottom. The j axis is horizontal and is numbered from left to right.
axis XY puts MATLAB into its default "Cartesian" axes mode. The coordinate system origin is at the lower left corner. The x axis is horizontal and is numbered from left to right. The y axis is vertical and is numbered from bottom to top.

Is there any way to change the xy positions in scatter graph in core plot

I am creating scatter graph, I need to change the x and y positions in scatter graph. Graph always starts with (0,0) positions but i need to show the starting points (7000, 800). Is there any way to change the x and y positions in scatter graph in core plot.
After showing the graph need to draw the line manually and get those values to search the properties.
Please help me.
Thanks in advance.
to set the point where the co-ordinates meet you have to set the orthogonal co-ordinate decimal
x.orthogonalCoordinateDecimal = CPTDecimalFromString(#"800");
y.orthogonalCoordinateDecimal = CPTDecimalFromString(#"740000");
and for setting the range of values to be plotted set the visibleRange for both the axes
These are features of the "plot space" in Core Plot. It defines the coordinate mapping between the plot area (basically the rectangle that contains all plot drawing) in data coordinates and the view in drawing coordinates. The xRange and yRange control the x and y range of the plot space, respectively.
The plot space converts coordinates in both directions—from data to view when drawing and from view to data when (for example) responding to touch events on a plot. See the plot space docs for a list of the available coordinate conversion methods.

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.