필터 지우기
필터 지우기

Using imref2d with reverse axes

조회 수: 4 (최근 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 CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by