- Display the Image: Use imshow to display your image.
- Set Preferences: Use iptsetpref to customize the image display preferences if needed.
- Capture Click Coordinates: Use ginput to get the coordinates where you want to set the new origin.
- Adjust Axes: Modify the axes to reflect the new origin and display relative distances.
xlabel change using point of the value of the ginput(1)
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a problem with making a image
I using imshow function to show image and iptsetpref function to make axes on the image.
After those process, I wanna change the x-axes and y-axes labels.
using x,y coordinates from ginput(1), I wanna re-draw the axes.
What I want to do is that making x,y coordinates from ginput(1) to [0,0]. from the standard point, I wanna to measure the relative distance from ginput(1) point
plz, help me.
thank you
0 个评论
回答(1 个)
Prateekshya
2024-10-17
Hello Seungyong,
To achieve your goal of setting a custom origin on an image and displaying relative distances using MATLAB, you can follow these steps:
Here is a step-by-step example:
% Load and display the image
img = imread('your_image.png'); % Replace with your image file
imshow(img);
hold on; % Keep the image displayed while adding other elements
% Get the point for the new origin using ginput
[x0, y0] = ginput(1);
% Calculate the size of the image
[imageHeight, imageWidth, ~] = size(img);
% Set new x and y limits for the axes
xLimits = [-x0, imageWidth - x0];
yLimits = [-y0, imageHeight - y0];
% Update the axes limits
set(gca, 'XLim', xLimits, 'YLim', yLimits);
% Update the x and y labels to reflect the new origin
xlabel('X (relative to selected point)');
ylabel('Y (relative to selected point)');
% Optionally, add a marker at the new origin
plot(0, 0, 'ro', 'MarkerSize', 10, 'LineWidth', 2);
% Add grid lines for better visualization
grid on;
This approach allows you to redefine the coordinate system of the displayed image based on an interactively selected point, making it easier to measure relative distances from that point. Adjust the code to fit your specific requirements or image dimensions.
I hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!