impoint and updating the coordinates

8 visualizzazioni (ultimi 30 giorni)
Pani
Pani il 26 Lug 2013
Risposto: Vidhi Agarwal il 5 Nov 2024 alle 7:08
I've created a gui, and there's a part where the user should be able to choose 2 pixel on the loaded image and then the program runs another function with the coordinates of those 2 pixels. I did it with ginput but now now I want to do it with impoint and I want also that the program updates the coordinates when the user changes those points. I just started to use Matlab, I would really appreciate if someone helps me.
x,y] = ginput(2)
handles.X = x;
handles.Y = y;
guidata(handles.PixelSelectionButt,handles)
[Xpath Ypath] = catetherPathFast((1-VessN).*im2double(I),y,x); axes(handles.ShowImage);
hold on
plot(Ypath,Xpath,'b-');
hold off

Risposte (1)

Vidhi Agarwal
Vidhi Agarwal il 5 Nov 2024 alle 7:08
Hi @Pani,
To achieve the functionality you described using "impoint" in MATLAB, you'll need to use the interactive capabilities provided by the Image Processing Toolbox. The "impoint" function allows users to place points on an image interactively and provides a way to retrieve and update the coordinates of these points. You can also set up listeners to automatically update the coordinates whenever the user moves the points. Below steps might help you in getting started.
  • Ensure your image is displayed in the appropriate axes within your GUI.
  • Use impoint to allow users to select and move points on the image.
% Create two interactive points on the image
hPoint1 = impoint(handles.ShowImage);
hPoint2 = impoint(handles.ShowImage);
  • Use "addNewPositionCallback" to update the coordinates whenever a point is moved.
% Add listeners to update coordinates when points are moved
addNewPositionCallback(hPoint1, @(pos) updateCoordinates(handles, pos, 1));
addNewPositionCallback(hPoint2, @(pos) updateCoordinates(handles, pos, 2));
  • Update the coordinates in your handles and use them to call your function.
% Function to update coordinates and run your custom function
function updateCoordinates(handles, pos, pointIndex)
% Update the coordinates in the handles structure
handles.X(pointIndex) = pos(1);
handles.Y(pointIndex) = pos(2);
guidata(handles.PixelSelectionButt, handles);
% Call your custom function with updated coordinates
[Xpath, Ypath] = catetherPathFast((1 - VessN) .* im2double(I), handles.Y, handles.X);
% Plot the path on the image
axes(handles.ShowImage);
hold on;
plot(Ypath, Xpath, 'b-');
hold off;
end
For better understanding of "impoint" and "addNewPositionCallback" refer to the following documentation:
Hope that helps!

Community Treasure Hunt

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

Start Hunting!

Translated by