How to use imtile, montage or any other methods to concatenate images without affecting the resolution?

17 Ansichten (letzte 30 Tage)
I would like to concatenate several figures, each with a different size, for example:
1010x25056x3 uint8 1515x24360x3 uint8 2020x95352x3 uint8
It looks that both imtile and montage are capturing thumbnail images for each image, so those with very huge size will be resized to fit the size of smaller ones.
Is there any possibilities to cancatenate those images and keep the original size for each.

Akzeptierte Antwort

DGM
DGM am 30 Sep. 2022
Bearbeitet: DGM am 30 Sep. 2022
If you're using IPT imtile() or montage(), you can maintain the geometry of each sub-image by making sure the 'thumbnailsize' option is large enough to contain any of the included images.
% two test images
A = imread('peppers.png');
B = rot90(A,1);
C = {A B}; % cell array of the images
% get union of image geometries
maxv = max(cellfun(@(x) size(x,1),C));
maxh = max(cellfun(@(x) size(x,2),C));
montage({A B},'thumbnailsize',[maxv maxh])
Bear in mind that this forces each sub-image to be padded horizontally and/or vertically to match the same geometry. If you're expecting to be able to have the images to only be padded along one dimension and edge-concatenated along the other, then IPT imtile()/montage() won't work afaik.
One option is to simply pad the images along the transverse dimension and then just concatenate them. This is simple and should work so long as all the images share the same depth (same size on dim3) and class. This example could be written to concatenate vertically as well.
% instead of using uniform tile geometries, simply stack along one
% dimension and pad only on the opposite dimension
% this example stacks on dim2 and pads on dim1 as necessary
% two test images
A = imread('peppers.png');
B = rot90(A,1);
C = {A B}; % cell array of the images
% get union of image geometries along transverse direction
maxsize = max(cellfun(@(x) size(x,1),C));
% pad all the images
for kimg = 1:numel(C)
padsize = (maxsize - size(C{kimg},1))/2;
C{kimg} = padarray(C{kimg},[floor(padsize) 0],0,'pre');
C{kimg} = padarray(C{kimg},[ceil(padsize) 0],0,'post');
end
C = horzcat(C{:});
There are also third party tools that can do this sort of flexible edge-stacking. MIMT imstacker() could be used, and may be more convenient. That said, it might be too expensive to use with such large images. Because imstacker() is meant to be class-agnostic, the output and intermediate working images will be of class 'double'. That sort of memory usage will likely be a problem for your particular needs.
% do the same thing using MIMT imstacker()
% two test images
A = imread('peppers.png');
B = rot90(A,1);
C = {A B}; % cell array of the images
% use MIMT imstacker() for a tight unidirectional stacking
outpict = imstacker(C,'dim',2,'padding',0,'gravity','center');
imshow(outpict)
% stack vertically instead
outpict = imstacker(C,'dim',1,'padding',0,'gravity','center');
imshow(outpict)

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by