MATLAB: Uipanel get and redraw image

guiimshowuipanel

I am wanting to change the scaling of an image already displayed in a uipanel.
This is my attempt
MM=get(handles.uipanelM,'Children');
J = imadjust(MM,stretchlim(MM),[0 1]);
%imshow(J);
imshow(J,'Parent',handles.uipanelM)
colormap(jet);
I can't figure out how to do it. thanks Jason

Best Answer

Jason - If we follow through with what you started (in above) then
MM=get(handles.uipanelM,'Children');
is the right idea but is making certain assumptions that may be invalid. Does your uipanelM only contain an axes for the image, or does it have other widgets as well? By calling get(handles.uipanelM,'Children');, we will be returned an array of handles to all graphics objects within the uipanelM widget. This may be one, two or more objects, so we can't assume that MM is only one handle, and it definitely won't be our image.
Since the image is already displayed, it must be displayed within an axes object, named (for example) axesM, which will be a child of the uipanelM widget. Rather than doing the above line of code which we would have to modify checking for two or more children, we can get the handle to the graphics object (of type image) that stores the image within the axes as
hImg = findobj('Parent',handles.axesM,'Type','image');
To get the image data, i.e. the mxnx3 (or whatever dimension) matrix, we can now do
if ~isempty(hImg)
% get the image data from the graphics object handle
imgData = get(hImg,'CData');
% adjust the image
J = imadjust(imgData,stretchlim(imgData),[0 1]);
% re-display the image back in the axesM
imshow(J,'Parent',handles.axesM);
colormap(jet);
end
In the above, we retrieve the image data from the axesM widget, adjust the image, and then re-display it back in the axesM widget (and so avoid the uipanelM altogether).