Filter löschen
Filter löschen

Using imref2d with reverse axes

4 Ansichten (letzte 30 Tage)
Luc Rébillout
Luc Rébillout am 3 Sep. 2014
Kommentiert: Luc Rébillout am 4 Sep. 2014
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.

Akzeptierte Antwort

Gitesh Nandre
Gitesh Nandre am 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 Kommentar
Luc Rébillout
Luc Rébillout am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by