How can i enlarge displayed images in a figure ?

8 Ansichten (letzte 30 Tage)
nissrine Neyy
nissrine Neyy am 13 Apr. 2022
Kommentiert: Image Analyst am 16 Apr. 2022
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

Akzeptierte Antwort

DGM
DGM am 14 Apr. 2022
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 Kommentare
nissrine Neyy
nissrine Neyy am 16 Apr. 2022
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 am 16 Apr. 2022
You could use either to specify only the first 100 images.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 13 Apr. 2022
Bearbeitet: Image Analyst am 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 Kommentare
Image Analyst
Image Analyst am 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
DGM am 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])

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by