Set the origin from bottom left corner of the image for ginput() function?
조회 수: 4 (최근 30일)
이전 댓글 표시
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
답변 (1개)
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Exploration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!