Set the origin from bottom left corner of the image for ginput() function?
4 views (last 30 days)
Show older comments
I saw many disccusions already for setting axes to bootom left.
This piece of code seems working for me:
I=imread("curved_river_wikipedia.jpg");
xlim([1 1025])
ylim([1 768])
imshow(I)
axis on
xlabel x
ylabel y
ax = gca;
ax.YDir = 'reverse';
hax = gca;
hax.YTickLabel = flipud(hax.YTickLabel);
But it doens't work for ginput(). The inner coordinates remain untouched.
0 Comments
Answers (1)
Deepak
on 3 Dec 2024
Hi Jiapeng,
To resolve the issue of “ginput()” not reflecting the visually flipped y-axis in MATLAB, we need to manually adjust the y-coordinates obtained from “ginput()” to match the visual representation.
This can be done by subtracting the y-values from the maximum y-limit and adding the minimum y-limit of the axis after using “ginput()”. This adjustment accounts for the axis inversion applied by setting “ax.YDir = 'reverse'”.
Below is the sample MATLAB code to achieve the same:
I = imread("curved_river_wikipedia.jpg");
xlim([1 1025]);
ylim([1 768]);
imshow(I);
axis on;
xlabel('x');
ylabel('y');
% Flip the y-axis visually
ax = gca;
ax.YDir = 'reverse';
% Get points using ginput
[x, y] = ginput();
% Adjust y-coordinates to account for the flipped axis
adjusted_y = ax.YLim(2) - y + ax.YLim(1);
% Display the adjusted coordinates
disp('Adjusted Coordinates:');
disp([x, adjusted_y]);
Please find attached the documentation of functions used for reference:
I hope this assists in resolving the issue.
0 Comments
See Also
Categories
Find more on Data Exploration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!