uipanel get and redraw image

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

 Accepted 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).

3 Comments

Hi Geoff, thanks for taking time to answer with your good explanaition.
Im not sure how to modify your line below
hImg = findobj('Parent',handles.axesM,'Type','image');
I draw a set of subplots (in a for loop) using the following
hp = handles.uipanelM;
h=subplot('Position',positionVector,'Parent',hp); %to enable deleting use handles
Jason
Hi Jason - you will want to either store the handles returned from the subplot calls into an array within the handles object, or you can try the following (which is more like what you started with)
% get the handles to the axes/subplots within the uipanelM
hAxes = findobj('Parent',handles.uipanelM,'Type','axes');
% decide which axes you want to do the adjustment on - if doing both
% then use a loop
for k=1:length(hAxes)
hImg = findobj('Parent',hAxes(k),'Type','image');
if ~isempty(hImg)
imgData = get(hImg,'CData');
J = imadjust(imgData,stretchlim(imgData),[0 1]);
imshow(J,'Parent',hAxes(k));
end
end
Perfect, thankyou. the trick was realising that each subplot has its own axes and that each one of these is represented by a handle, hence there are many handles.
So the hieracy is uipanel->axes->image->CData

Sign in to comment.

More Answers (0)

Categories

Find more on Display Image in Help Center and File Exchange

Asked:

on 29 Sep 2014

Commented:

on 29 Sep 2014

Community Treasure Hunt

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

Start Hunting!