- it's basic geometry
- default subplot() behavior wastes tons of space
How can i enlarge displayed images in a figure ?
9 views (last 30 days)
Show older comments
I want to display a total of 100 images (they have different sizes) in a figure. when i do so the images are shrinked a lot, so i want to enlarge them a bit just so that they'd be visible. (a screenshot of the figure is bellow) and here's my code :
figure('Name','Retrieved images','NumberTitle','off');
for i = 1:100
subplot(5,20,i);
imshow(imread(fullfile('C:\Users\viet\Desktop\image.orig',meanValuesW(i).baseFileName)));
end
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/963305/image.png)
0 Comments
Accepted Answer
DGM
on 14 Apr 2022
The problem has nothing to do with imshow(). It's two things:
Regarding #1, you have 100 images, the majority of which are landscape orientation with an AR of about 3/2. You are tiling them 20/5 in a figure with an AR of about 2/1. There will obviously be a huge gap between the rows. There necessarily must be. Either change the tiling or change the figure aspect ratio.
Regarding #2, either you have to manually tweak position properties in order to make subplot() make better use of space, or you have to use something else. You can try using tiledlayout(). It's slower, but it has more options for making good use of space. It's relatively new, so the old version I have is flaky and not all those said options are supported. I can't really craft a fully-complete solution because of that. You'll have to play around with it yourself:
% test images
L = ones(66,100); % landscape AR 3/2
P = ones(100,66); % portrait AR 2/3
imgs = {L P};
% there are 14 portrait images, 100 total
idx = ones(100,1);
idx(1:14) = 2;
idx = idx(randperm(100));
% maybe use a tiling that's closer to square
% extra slots are simply unused
tiledlayout(6,17,'tilespacing','none','padding','none')
for k = 1:100
nexttile
imshow(imgs{idx(k)}*rand(1)*0.5+0.25);
end
Like I said, you'll have to find a figure aspect ratio or a tiling that makes for good density.
Look at tilespacing and padding options:
2 Comments
More Answers (1)
Image Analyst
on 13 Apr 2022
Edited: Image Analyst
on 13 Apr 2022
Maybe try imshow with the 'Border', 'Tight' option.
figure('Name','Retrieved images','NumberTitle','off');
for i = 1:100
subplot(5,20,i);
thisFileName = fullfile('C:\Users\viet\Desktop\image.orig',meanValuesW(i).baseFileName);
rgbimage = imread(thisFileName);
imshow(rgbimage, 'Border', 'tight');
end
Or try using imtile() or montage().
3 Comments
Image Analyst
on 14 Apr 2022
I'm pretty sure montage() or imtile() don't leave tons of gray space around each image. Post a screenshot of how it looked for you.
DGM
on 14 Apr 2022
Same as in my example, but with montage()
% test images
L = ones(66,100); % landscape AR 3/2
P = ones(100,66); % portrait AR 2/3
imgs = {L P};
% there are 14 portrait images, 100 total
idx = ones(100,1);
idx(1:14) = 2;
idx = idx(randperm(100));
% build a cell array of images
C = cell(100,1);
for k = 1:100
C{k} = imgs{idx(k)}*rand(1)*0.5 + 0.25;
end
montage(C,'size',[8 13])
See Also
Categories
Find more on Image Processing Toolbox 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!