Show img in coordinate system and perform transformations
1 view (last 30 days)
Show older comments
I want to show my image in xy-coordinate system, Now I have img and I can read it without any problem
I = imread('img.png');
size(I); % 16 x 15
imshow(I);
Now the img shows like this,
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1564159/image.png)
Now I wanted it to be shown like a graph with proper x,y coordinates.
For example the size of img is 16x15 and corners of the img by default should be as
Bottom Left: (0,0)
Bottom Right: (16, 0)
Top Left: (0, 15)
Top Right: (16, 15)
Now, comes the real part. img is displayed in coordinate system with these points.
Now I want to perform transformations, I will try to explain it in detail with example
For example I am given a scenerio
Apply Shear of factor 2 in y direction. Now first we find the Standard matrix and then get new coordinates
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1564164/image.png)
The 2nd is the Standard matrix while thrd is the unit vector (img in our case) and fourth is the transformed vector.
I want to do this with the img, using Standard matrix getting new coordinates and displaying img accordingly. I can show it mathematically in detail.
Now the standard matrix will be
T = [1 0
2 1] % from the above img
Now new coordinates would be
Bottom Left = T * [0; 0] = [0; 0]
Bottom Right: (16, 0) = T * [16; 0] = [16; 32]
Top Left: (0, 15) = T * [0; 15] = [0; 15]
Top Right: (16, 15) = T * [16; 15] = [16; 47]
Now, I have the new coordinates, I want the img to be displayed according to the new coordinates. This is the end goal I want to acheive. I would have to apply different Standard matrixes at different ocations, so do not want the solution to work only for shear factor.
2 Comments
Catalytic
on 10 Dec 2023
You asked essentially the same question and got essentially the same answers in this earlier post. Why did you abandon it?
Accepted Answer
Matt J
on 9 Dec 2023
Edited: Matt J
on 10 Dec 2023
I=flipud(imread('peppers.png'));
T = [1 0
2 1]; T(3,3)=1;
[Iw,R]=imwarp(I, affine2d(T'));
h=imshow(Iw);
axis on xy;
set(h,'XData',R.XWorldLimits,'YData',R.YWorldLimits);
set(gca,'XLim',R.XWorldLimits,'YLim',R.YWorldLimits);
4 Comments
Matt J
on 10 Dec 2023
The axis is set on after the img is shown, I think this is causing the wrong xy position in reflection case
I fixed it.
Also, can you explain this a bit so I can try it my self too
I would need specific questions. imwarp does all the work, so you should definitely read that doc page thoroughly.
More Answers (1)
Image Analyst
on 9 Dec 2023
"I want to show my image in xy-coordinate system" <== Did you try calling axis xy?
axis xy
Call it after you call imshow.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!