How to add image overlay in GUIDE ?
14 views (last 30 days)
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)
image1=reshape(handles.nii.img(handles.cursor(1),:,:), dims(2), dims(3));
% like that my image is displayed, how to overlay a second one?
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.
Adam on 1 Mar 2019
Edited: Adam on 1 Mar 2019
(Original comment prepended to the answer for the last comment):
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)
Make sure you use explicit axes handles when using all plotting-based instructions also. Most plotting functions (and things like hold, xlim, axis, etc) have a syntax that allows you to pass in an axes handle as the first argument and then the remaining arguments are exactly as you would use them otherwise.
This ensure that your instructions are being applied to the axes you expect.
applies hold on status to the current axes. Is the current axes actually the one you think it is at that moment? Don't take that risk. Give it an explicit instruction:
hold( hAxes, 'on' )
where hAxes is your axes handle, e.g. handles.axes1 is the default handle for the first axes in GUIDE, but this will be whatever you set its tag to.
I didn't notice until I scrolled just now actually that you are already doing this for plotting the original image, which is good, so just do it with the hold instruction too and you should be fine.