How to rearrange images within imtile and/or montage?
27 views (last 30 days)
I'm trying to use the image processing toolbox to arrange about 600 various aerofoil images into the layout (final size 1400 X 460) depicted below:
I currently have a 4 groups of images with the following dimensions:
- Validation Full: 1400 X 460
- Validation LE (leading edge): 200 X 460
- Validation TE (trailing edge): 450 X 460
- Validation Camber: 750 X 460
These are in various subfolders within one parent folder, that I'm accessing using an imagedatastore. I haven't got any experience with image processing, but this is what I've got so far (I've replaced my folder paths with ...... for privacy, and merely left the final folder names.
This results in the following picture:
I believe it's loaded all the desired images into a singular tile, but not in the arrangement required. How can one manipulate the constituent images into the format above? And furthermore, could this function be placed in a 'for' statement, and used repetitively for all ~600 images?
imds = imageDatastore('.......Validation mesh pics', ...
Main = '...........Validation Full';
TE = '.............Validation TE';
LE = '.............Validation LE';
Camber = '.........Validation Middle';
fileMain = fullfile(Main,'image0004.jpg');
fileTE = fullfile(TE, 'image0004.jpg');
fileLE = fullfile(LE, 'image0004.jpg');
fileMid = fullfile(Camber, 'image0004.jpg');
readMain = imread(fileMain);
readTE = imread(fileTE);
readLE = imread(fileLE);
readMid = imread(fileMid);
multi = cat(2,readMain,readTE,readLE,readMid);
Full = montage(multi,'Size',[2 3],'DisplayRange',);
ShowMain = imshow(montage);
DGM on 15 Mar 2021
Edited: DGM on 12 Oct 2022
I'm not really sure what your question is. You are loading four images into the WS and then you concatenated them into a single image. The images are a single image because you concatenated them into one.
My understanding is that imtile() and montage() can accept a multiframe stack of images (i.e. a rows x columns x channels x frames array), or they can accept a cell array of filenames -- but in either case, the image tiles (the blocks within the output image) must have compatible height and width to be tileable. In both cases, these tools pad or crop the input images to meet that constraint. I doubt this is really what you want. Resizing to meet the geometry constraint is likely preferred.
There are probably various solutions. If you can rely on your image sizes being fixed, you can just tile them manually into a single image. Here, I'm assuming that your geometry specifications are backwards. (i.e. that the images are all 460px tall)
% calculate width of top row
imwidth=size(readMain,2) + size(readTE,2) + size(readLE,2);
% resize the fourth image to match the top row width
% consider the interpolation method used based on the image content
% concatenate the images
% show the result
If you want padding between the images, you can pad them (e.g. using padarray()) prior to tiling, or you can explicitly generate padding blocks to concatenate between the images. If the image height can't be relied upon to be consistent, you can compensate for any height mismatch in the padding process, that way the padded images can be tiled.
And yes, there's no reason this can't all be done in a loop