Using imref2d with reverse axes

3 次查看(过去 30 天)
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.

采纳的回答

Gitesh Nandre
Gitesh Nandre 2014-9-4
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 个评论
Luc Rébillout
Luc Rébillout 2014-9-4
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by