Get the position of a single freehand ROI on axes with a click
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi there,
I have drawn three freehand ROIs on an UIaxes and I want to use the tools options to click on one ROI and extract the information assosite with it in the command line (e.g., position, color , etc). Is there any way to perform this?
I know an ultimate option is to save each ROI into a variable after using the drawfreehand function. But for the purpose of my work i must insits on extracting this information directly on UIaxes with a click.
I would highly appreciated if someone could help me with this.
Best,
Nikan
댓글 수: 0
답변 (1개)
Githin George
2024년 2월 9일
Hello,
I have played around with some basic code snippets in MATLAB R2023a, to see if the data related to the ROI can be displayed in the MATLAB command window, by clicking on them in the uiaxes. This can be done by making use of the “addlistener” function to add an event callback for the “ROIClicked” event.
An example code snippet is provided below.
fig = uifigure;
ax = uiaxes('Parent', fig);
% Draw three freehand ROIs on the UIAxes
roi1 = drawfreehand(ax, 'Color', 'r');
roi2 = drawfreehand(ax, 'Color', 'g');
roi3 = drawfreehand(ax, 'Color', 'b');
% Add event listeners for the ROIs
addlistener(roi1, 'ROIClicked', @roiClicked);
addlistener(roi2, 'ROIClicked', @roiClicked);
addlistener(roi3, 'ROIClicked', @roiClicked);
% callback function to be called during ROI Click
function roiClicked(src, ~)
% src is the ROI that was clicked
pos = src.Position;
color = src.Color;
disp('ROI clicked:');
disp(['Position: ', mat2str(pos)]);
disp(['Color: ', mat2str(color)]);
end
You can also try and automate the code where the listener is added so that the end user need not worry about capturing the “ROI” handles into variables.
For more information on “addlistener” function and ROI related events, please have a look at documentation links below.
I hope this helps.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!