MATLAB Answers

How to rearrange images within imtile and/or montage?

조회 수: 26(최근 30일)
Sho Wright
Sho Wright 2021년 3월 15일
댓글: Sho Wright 2021년 3월 20일
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,
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 2021년 3월 15일
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() expect their inputs to have consistent geometry. They 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 images must have consistent height and width to be tileable. If you want to use montage, you'll have to pad your images to a common geometry. I doubt this is really what you want.
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
% 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
  댓글 수: 3
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개)

Community Treasure Hunt

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

Start Hunting!

Translated by