How can i enlarge displayed images in a figure ?

12 次查看(过去 30 天)
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

采纳的回答

DGM
DGM 2022-4-14
The problem has nothing to do with imshow(). It's two things:
  1. it's basic geometry
  2. default subplot() behavior wastes tons of space
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 个评论
nissrine Neyy
nissrine Neyy 2022-4-16
Thank you so much Image analyst and DGM for your answers, would this method work in my case in which i'm trying to display only the first 100 images in the struct array i have ?
Image Analyst
Image Analyst 2022-4-16
You could use either to specify only the first 100 images.

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2022-4-13
编辑:Image Analyst 2022-4-13
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 个评论
Image Analyst
Image Analyst 2022-4-14
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
DGM 2022-4-14
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])

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

标签

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by