How to rearrange images within imtile and/or montage?

5 次查看(过去 30 天)
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?
Many thanks,
Sho
imds = imageDatastore('.......Validation mesh pics', ...
'IncludeSubfolders',true,'FileExtension','.jpg','LabelSource','foldernames');
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
DGM 2021-3-15
编辑:DGM 2022-10-12
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
readMid=imresize(readMid,[NaN imwidth],'bicubic');
% concatenate the images
tiledpic=cat(2,readMain,readTE,readLE);
tiledpic=cat(1,tiledpic,readMid);
% show the result
imshow(tiledpic);
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
  3 个评论
DGM
DGM 2021-3-16
Sure. You can pad any dimension with padarray. I admit, the syntax is a bit cumbersome.
If I want to add 3px of padding to the top only:
padarray(mypicture,3,0,'pre');
If I want to add 3px of padding to the right side only:
padarray(mypicture,[0 3],0,'post');
If I want to add 3px to the top and bottom and 4px to the left and right
padarray(mypicture,[3 4],0,'both');
This sometimes gets awkward. Say I want 3px padding on top and 4px on bottom. I can't do that in a single pass.
padarray(padarray(mypicture,3,0,'pre'),4,0,'post')
Sho Wright
Sho Wright 2021-3-20
Sorry for the late response,
I managed to get the final result I originally wanted, thank you very much for your time and help!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Feature Detection and Extraction 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by