Hiding the drag points on a Matlab images.roi.Circle, and other ways of using ROIs as selection masks

9 次查看(过去 30 天)
Hello All,
TLDR at bottom
This question applies more broadly to the new Matlab images.roi objects, but I realized that the ROI's are ideally set up to create selection bit-masks in an image. I can throw some arbitrary graphic into a figure, put an ROI below it, and use the ROI interface to determine when I mouse-over and click on that region. Depending on my needs I could also make my inset area draggable and stretchable depending on how I link in my ROI's callbacks for movingROI and roiMoved. If I wanted to rebuild Myst in Matlab, this is how I would do it.
However, the sticky wicket is that you cannot as far as I can tell make an invisible ROI; the current format insists on drawing a border, and for some ROI objects it forces the appearence of drag points. Here is an example:
I = imread('cameraman.tif');
imshow(I);
ax = gca;
circ = images.roi.Circle(ax,'Position',[114 60],'Radius',30);
Ok, so I have a nice circle ROI centered on the camerman's head. I can make the center invisible via
set(circ,'FaceAlpha',0)
However, both the border and the drag points are still visible: I cannot find a property or method to disable them!
Well, I can always set the circle to be invisible
set(circ,'visible','off');
BUT this not only makes the circle visibly vanish, but also means that all of the interactions it came with are not accessible; I can only translate/etc the ROI programattically, not through the UI. Thus it makes a really poor selection mask.
I hoped that another option would be to limit us to translation:
set(circ,'InteractionsAllowed','translate');
Thus, the drag points are no longer necessary...but they are still visible!
Ok, so I do know that it is possible to hide the drag markers, using
set(circ,'InteractionsAllowed','none');
BUT, again this makes my ROI useless, as I cannot interact with it in any way.
I thought I had a genius moment, and added a listener that would only enable interactions when the ROI was selected:
addlistener(circ, 'ROIClicked', @(s,evtData) selectListener(s,evtData));
function selectListener(s,evtData)
selectedPart = evtData.SelectedPart
prevselected = evtData.PreviousSelected
if selectedPart && ~prevselected
set(circ,'InteractionsAllowed','Translation');
else
set(circ,'InteractionsAllowed','none');
end
Once again...failure. I cannot select an ROI with no interactions allowed; the istener is never called. I have to allow translations, stretching, or both.
This causes other potential issues, if I want to programattically draw an ROI and have some callback when selected but not allow moving the ROI, I have to lock the ROI in place using the movingROI callback rather than simply disabling the two movements; there should be a "no movement, but allow selection" setting, but I digress.
One kludge does let me at least get rid of the hideous drag buttons, but still leaves the outline (and is just plain dumb):
msk = images.roi.Freehand(ax,'Position',circ.Vertices,'Waypoints',false(size(circ.Vertices,1),1),'FaceAlpha',0,'LineWidth',.1);
delete(circ);
----------------------------------------------
TLDR - I want to create an invisible but still interactable ROI using the images.roi toolbox. This requires hiding the outline and the drag points. I cannot do this and retain interactability. Is there a workaround?
Cheers,
-Dan
---------------------------------------------
P.S. I really dislike p-code. I understand the reason for it, but not being able to change simple properties and behaviors (such as making the drag points invisible) and not being able to figure out why is infuriating.
  3 个评论
sr123
sr123 2024-6-5
I appreciate you mentioning set(circ,'InteractionsAllowed','none'), as this does the job for me and it wasn't clear from documentation. I was really surprised there is no way of editing the appearance of the markers, other than their size... seems like missing functionality.

请先登录,再进行评论。

回答(1 个)

Matt J
Matt J 2023-10-30
circ.EdgeAlpha=0;
circ.FaceAlpha=0;
  4 个评论
sr123
sr123 2024-6-5
Fair enough - I was after hiding the markers/drag points, which I assumed OP meant, as per the post title.
For argument's sake, is your solution any different than set(circ,'visible','off'); ? Because OP did manage to make the circle invisible that way, but it did not seem to be what they were after.
Matt J
Matt J 2024-6-5
My solution is different, because you can still interact with the invisible ROI.
If you want to hide the boundary of the ROI and its markers, but still want the ROI to have some visibility, you could modify my solution by adding a semi-transparent fill color to the circle, e.g.,
I = imread('cameraman.tif');
imshow(I);
ax = gca;
circ = drawcircle(ax,'Center', [167 143],'Radius',30,...
'EdgeAlpha',0,'FaceAlpha',0.3, 'Color','red');

请先登录,再进行评论。

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by