Clear Filters
Clear Filters

Using imref2d with reverse axes

4 views (last 30 days)
Good morning,
I have a picture impiv of size 2004*1218*3 and I know the world coordinates of every corner of the pictures :
(-2,41) (-26,41)
+-----------------------------------+
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
+-----------------------------------+
(-2,-1) (-26,-1)
I also know the x and y resolution :
sc_x = sc_y = 0.02 (cm/Px)
I want to use imref2d to display my picture in the world coordinate system so I said
ymax = 41
ymin = -1;
yWorldLimits = [ymin, ymax];
xmin = -26 ;
xmax = -2 ;
xWorldLimits = [xmin, xmax];
imageSize = size(impiv1);
R = imref2d(imageSize,xWorldLimits,yWorldLimits);
imshow(impiv,R);
But then my axes are in the reverse order as I want them (see picture below) and if I try to flip
xWorldLimits
and
yWorldLimits
I get an error saying that the values must be in ascending order.
Does anybody have an idea on how to procede ? Thank you.

Accepted Answer

Gitesh Nandre
Gitesh Nandre on 4 Sep 2014
In the first diagram of the picture in the world coordicate system, you have shown point (-2,-1) to the left side of point (-26,-1). It should be in other direction because (-2) > (-26). Hence your picture in world coordinate system should be like below.
(-26,41) (-2,41)
+-----------------------------------+
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
+-----------------------------------+
(-26,-1) (-2,-1)
Now, it is clear that X-axis for final output shown in your case is correct. However, Y-axis is reversed and it is not what you are expecting. Origin setting in upper-left corner is a default one and for plotting images it makes sense. For matrix plotting, you want it to be at lower-left corner. We can flip Y-axis in following two ways:
Flip 'impiv' upside down and draw xy axes in default cartesian axes format.
imshow(flipud(impiv),R);
axis xy;
Another way is to flip YTick labels as follows:
ylims = get(gca,'YLim'); %get y limits for current axes
yticks = get(gca,'YTick'); %get y-ticks
flipped_yticks = ylims(2)-yticks; ...
%flip ticks by subtracting from upper limit
set(gca,'YTickLabel',num2str(flipped_yticks'));
You will get final result as follows:
  1 Comment
Luc Rébillout
Luc Rébillout on 4 Sep 2014
Thank you, but my coordinates are correct according to my experimental setup. But I can just use the same trick you used for the y axis.

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!