Using imref2d with reverse axes

5 ビュー (過去 30 日間)
Luc Rébillout
Luc Rébillout 2014 年 9 月 3 日
コメント済み: Luc Rébillout 2014 年 9 月 4 日
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 Center および File ExchangeGraphics Object Programming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by