Set the origin from bottom left corner of the image for ginput() function?

14 ビュー (過去 30 日間)
Jiapeng Zhang
Jiapeng Zhang 2020 年 3 月 3 日
回答済み: Deepak 2024 年 12 月 3 日
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.

回答 (1 件)

Deepak
Deepak 2024 年 12 月 3 日
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.

カテゴリ

Help Center および File ExchangeData Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by