Screen capture area on UIpanel?

4 views (last 30 days)
Jason
Jason on 2 Oct 2014
Commented: Geoff Hayes on 5 Oct 2014
Sorry for an extension of previous question but I thought it deserves a new thread.
I am plotting images as thumbnails to form a montage.These are all plotted on a UIPanel in a loop, and there are typically 6 columns x 8 rows of thumbnail images.
Previously, I wanted to redraw all of these with a different scaling if required uisng:
% 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
This works well, but I was wondering can I get the whole montage as a single entity rather than have to loop through the handles and address each on seperately. The reason being is I want to then take this set of "montaged" images, and shrink and place on another figure of UIPanel. I guess Im asking if its possible to do a sort of "screen capture"?
Thanks Jason
  1 Comment
Jason
Jason on 2 Oct 2014
Edited: Jason on 2 Oct 2014
Maybe the way I create the montaged image by displaying one image at a time shrinked and on a UIPanel is not the best approach as then I have many handles to deal with?

Sign in to comment.

Answers (1)

Geoff Hayes
Geoff Hayes on 2 Oct 2014
Hi Jason - perhaps I'm misunderstanding what you want, but if you want to create one image that is the combination (montage) of all images from each of the subplots that are arranged in 8 rows of 6 columns, then you could do something like the following. Note that the assumption here is that each image is of the same dimension. If this assumption is invalid, then you can modify the code to resize each image to some fixed mxnx3 dimension using imresize.
First create some random images arranged in an 8x6 subplot grid
% generate mxn subplots with solid colour images
close all;
figure;
m = 8;
n = 6;
hAxes = [];
for u=1:m
for v=1:n
hAxes(u,v) = subplot('Position',[(v-1)/n 1-(u/m) 1/n 1/m]);
image(repmat(uint8(randi(255,1,1,3)),100,200,1),'Parent',hAxes(u,v));
set(hAxes(u,v),'XTick',[],'YTick',[]);
end
end
So this will give us our 48 subplots on the figure where each subplot contains a 100x200x3 image of a solid colour.
Now we just take the image from each subplot and combine it into a larger image
% create a montage
allImgs = cell(m,n);
for u=1:m
for v=1:n
hImg = findobj('Parent',hAxes(u,v),'Type','image');
allImgs{u,v} = get(hImg,'CData');
end
end
figure;
montageImg = cell2mat(allImgs);
image(montageImg);
set(gca,'XTick',[],'YTick',[]); % remove the ticks
We collect the images from each subplot into a cell array, and then convert that into a matrix/image which is just the combination of all subplot images.
Note how that hAxes is a 8x6 matrix of handles versus the one-dimensional array that you are using. I found that the 2D approach is a little easier since I know exactly where each subplot is, and so know where each image should go in the montage.
  8 Comments
Jason
Jason on 5 Oct 2014
Thankyou Geoff, it was the flipud thats corrected it. Thanks for all your time. Jason
Geoff Hayes
Geoff Hayes on 5 Oct 2014
Glad that you got it working, Jason!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!