How to add image overlay in GUIDE ?
Show older comments
Hello!
I am trying to overlay markers on an image displayed in a GUI. I tried to have my markers in a matrix which I would like to overlay on my image but couldn't find the way to do that. Coulc you please help me?
I am displaying the main image on axes, from the slider callback which is looking like that:
function slider3_Callback(hObject, eventdata, handles)
% ...
dims=size(handles.nii.img);
handles.cursor(1)=int16(get(hObject, 'Value'));
image1=reshape(handles.nii.img(handles.cursor(1),:,:), dims(2), dims(3));
imghandle=findobj(handles.axes1, 'Type','image');
set(imghandle, 'CData',image1');
% like that my image is displayed, how to overlay a second one?
% ...
guidata(hObject,handles)
doCommonUpdate(handles,'x')
end
I tried to 'hold on' and add the second image in 'CData' and then modify the transparency of this second image with 'AlphaData' but the overlay image is not an overlay and it takes the place of my primary image.
2 Comments
The CData is of your original image. If you add a second image in addition to your original and set the AlphaData on that instead then you will have both images and the second one will have tramsparency defined by the AlphaData while the original will be full opaque underneath it - i.e. visible anywhere the AlphaData of the second image is < 1 (to varying degrees, and clearly where AlphaData is 0)
You should get used to using graphics handles returned by calls to things like imagesc or image or imshow ideally and keep hold of these for further use rather than having to do a findobj to relocate them. In many cases it doesn't matter, but if performance is an isse then having to search for objects that you could just access directly is not ideal.
Emilie Mussard
on 1 Mar 2019
Accepted Answer
More Answers (0)
Categories
Find more on Images 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!