How can I toggle a transparent image overlaid on another image?
1 view (last 30 days)
Show older comments
Within my GUI, I have an image on a set of axes. I need to be able to toggle a 3x3 grid of points on and off, so that they display overtop of the image when a checkbox is checked, and disappear when the checkbox is unchecked.
In order to achieve this I tried to set the AlphaData matrix to the appropriate alpha matrix when the checkbox is ticked, and to a zero matrix of the same size when unchecked.
function targetGridCheck_Callback(hObject, eventdata, handles)
[a,map,alpha] = imread('dot-grid-3x3_768x768.png');
I = imshow(a,'Parent',handles.axes2);
if (get(hObject,'Value') == get(hObject,'Max'))
set(I,'AlphaData',alpha);
else
set(I,'AlphaData',zeros(size(I)));
end
With this code, ticking the checkbox shows the grid, but also vanishes the background image. When the checkbox is unticked the background image stays gone (the axes are completely blank).
How do I keep the background image in all cases?
0 Comments
Answers (1)
Image Analyst
on 16 Jul 2018
Why not just clear the lines using a function like this:
%=====================================================================
% Erases all lines from the image axes h (which could be gca).
function ClearLinesFromAxes(h)
axesHandlesToChildObjects = findobj(h, 'Type', 'line');
if ~isempty(axesHandlesToChildObjects)
delete(axesHandlesToChildObjects);
end
return; % from ClearLinesFromAxes
Then just draw your 3x3 grid again with line() when you want to show it again. That's what I'd do.
2 Comments
Image Analyst
on 17 Jul 2018
plot() can draw points. Just don't specify a line style
plot(x, y, 'b.', 'MarkerSize', 20); % plot blue dots
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!