uipanel get and redraw image

3 views (last 30 days)
Jason
Jason on 29 Sep 2014
Commented: Jason on 29 Sep 2014
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

Geoff Hayes
Geoff Hayes on 29 Sep 2014
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
Geoff Hayes
Geoff Hayes on 29 Sep 2014
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
Jason
Jason on 29 Sep 2014
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 Environment and Settings 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!