xlabel change using point of the value of the ginput(1)

2 views (last 30 days)
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

Answers (1)

Prateekshya
Prateekshya on 17 Oct 2024
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:
  1. Display the Image: Use imshow to display your image.
  2. Set Preferences: Use iptsetpref to customize the image display preferences if needed.
  3. Capture Click Coordinates: Use ginput to get the coordinates where you want to set the new origin.
  4. Adjust Axes: Modify the axes to reflect the new origin and display relative distances.
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!

Categories

Find more on Convert Image Type 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!