Set the origin from bottom left corner of the image for ginput() function?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Deepak
il 3 Dic 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 Commenti
Vedere anche
Categorie
Scopri di più su Data Exploration in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!