Matlab: mirror results along xaxis - matlab

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.

Related

What are the Coordinate Axes alignment in plot generated by quiver

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)

plotting is displayed upside down at MATLAB GUI

I am working on video surveillance on crowd density estimation. I am implementing a corner detection method for this project. However, I have a problem when my code is combined in GUI MATLAB, the display of plotting corner is upside down and it is not overlay on the original image. Here my code on plotting the image in GUI Matlab.
The problem is solved already and here is the correct code:
% Find row,col coords.
[r,c] = find(cim2);
%After getting row and column coordinate, I plot them together in the original image which is
% overlay image and plotting
imshow(inFrame, 'Parent', handles.axes8);
hold on;
p1 = plot([c],[r],'r.');
set(p1, 'Parent', handles.axes8);
Thank you for #Lokesh for his suggestion.
The explanation of your problem is very well given by floris.But here due to lack of full your code we are not able to perform it on our system. you can aslo try for
axis ij
which is some what similar to above answer. you can also try the below code.
imshow(inFrame,'Parent',handles.axes8);
hold on;
p1 = plot([c],[r],'r.');
set(p1,'Parent',handles.axes8);
hope this works for you..let me know about the result..
imshow inverts the Y axis. Conventionally, in image display the top left corner of the screen is (0,0) with i (the first coordinate) running down the screen, and j (the second coordinate) from left to right.
If you want the image axis to look like a conventional plot axis you can do
axis xy
This will "invert" your image, putting 0,0 in the bottom left.

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

double axis used in matlab

I am using a plotyy in matlab to plot two data set in a same figure. The left and right axis are of the different range. But I just find that on the right axis, there seems to be two different set of scale shown. I think one of them is really from the left axis.
t=-1:0.02:1;
y=sin(t);
y1=2*sech(t);
[AX, H] =plotyy(t, y, t, y1);
ylim(AX(2), [0 3.25]);
set(AX(2), 'YTickMode', 'auto')
After searching that online, I found that to turn off the box will solve the problem too. But the problem is to turn the box off will case the top horizontal line gone also. Is that anyway to remove the extra scale and keep the frame? Thanks.
It is possible and not terribly difficult, here's an illustrative example figure based on your test code
What I've done is to add a third axis (in this case I accomplished this by taking a shortcut - I called plotyy twice resulting in an extra blue line in the first axis and an extra second axis with a green line).
The idea is to turn the bounding box off for both the first and second axes, and then to turn it on for the third. That results in the top axis giving you the left vertical axis, the second the right vertical axis, and the third the top horizontal axis.
I don't think there's simple a way to do what you want. If you turn off the box (to get rid of the blue ticks on the right hand side) then the top horizontal line will disappear:
set(AX(1), 'Box','off')
If you want you could re-draw the line back in with:
line([-1, 1], [1, 1])
Or more generally:
lims = get(AX(1),{'XLim','YLim'});
line(lims{1}, lims{2}([2 2]))

How do I edit the axes of an image in MATLAB to reverse the direction?

I would like to edit the axes in my series of images being displayed.
This is what my image looks like:
As you can see, it ranges from 0 to about 500 from top to bottom. Can I invert that?
Plus, I want to mirror the image being shown, so that it starts from left to right... or, if it's possible, to let the axes show from right to left.
To reverse an axis, you can set the 'XDir' or 'YDir' property of the current axes to 'reverse':
set(gca,'XDir','reverse'); %# This flips the x axis
Keep in mind that flipping an axis in this way flips everything in the plot as well. This probably isn't what you want to do for the y axis. You probably just want to flip the y axis labels, which you can do by modifying the 'YTickLabel' property in the following way:
yLimits = get(gca,'YLim'); %# Get the y axis limits
yTicks = yLimits(2)-get(gca,'YTick'); %# Get the y axis tick values and
%# subtract them from the upper limit
set(gca,'YTickLabel',num2str(yTicks.')); %'# Convert the tick values to strings
%# and update the y axis labels
Im = imread('onion.png');
Im = flipdim(Im ,1); % vertical flip the image.
axis xy; %set the xy to be at (0,0), this flips the image back again.
And whoop dee doo the image now have an y axis with the range from bottom to top!
How can I reverse the y-axis when I use the IMAGE or IMAGESC function to display an image in MATLAB? Another solution from mathworks
I found gnovice's answer helpful but it needed some tweaks for me. I think the following is a more general way to reverse the labels on the y axis. Simply sort the y tick numbers in descending order and relabel.
yTicks = get(gca,'YTick');
yTicks_reverse = sort(yTicks,2,'descend');
set(gca,'YTickLabel',num2str(yTicks_reverse.'));
I was redirected here from a duplicate question:
Flipping axis ticks
What 'ale' wanted to do there was just to flip the y-axis direction to be top down. If that is the only thing needed and nothing else, I would use:
axis ij