Align & Distribute Multiple images in An image

4 views (last 30 days)
I need to Align & Distribute multiple small images evenly in a big image. Just need "positioning", don't need to rotate or skew any image. More specifically, i need to distribute multiple SMALL images all on single Big image (which will be considered as Background image for all those small objects).
Found something extremely useful (here at https://www.mathworks.com/help/matlab/ref/align.html), but not sure (infact don't know) how to use it to distribute/align images,
Need Help, Thanks

Answers (1)

Gopichandh Danala
Gopichandh Danala on 26 Jun 2017
Edited: Gopichandh Danala on 26 Jun 2017
If I understood correctly you don't want to display multiple images in a single figure axis as in SUBPLOT or MONTAGE, instead you want to create a background image (Matrix) to fit all these small images into it as of your requirement.
Matlab doesn't have any built-in functions to do this, but you can write some hard written code to address this requirement.
I am writing some sample code which aligns five images with 3 and 2 images in each row respectively, you can modify it to fit your criteria.
% Five random images..
I1 = rand(100);
I2 = rand(20,50);
I3 = rand(80);
I4 = rand(60,20);
I5 = rand(120);
% size of each image..
[r1, c1] = size(I1);
[r2, c2] = size(I2);
[r3, c3] = size(I3);
[r4, c4] = size(I4);
[r5, c5] = size(I5);
% Now get the max Image size for the background..
% I am considering 3 images in first row and 2 images in second row..
% First Row cords
Rows1 = [r1, r2, r3];
Cols1 = [c1, c2, c3];
maxRows1 = max(Rows1);
MaxRows1 = max(Rows1);
MaxCows1 = sum(Cols1);
% Second Row cords
Rows2 = [r4, r5];
Cols2 = [c4, c5];
MaxRows2 = max(Rows2);
MaxCols2 = sum(Cols2);
% Max BackGround Size
BGRows = sum([MaxRows1,MaxRows2]) + 30; % 30 extra rows to leave uniform spaces..
BGCols = max(MaxCows1,MaxCols2) + 40; % 40 extra cols to leave uniform spaces..
% BackGroundImage
BG_Image = zeros(BGRows, BGCols);
% Map these five images onto background..
% First Row
BG_Image(11:c1+10,11:r1+10) = I1;
BG_Image(11: r2+10 , c1+21:c1+c2+20 ) = I2;
BG_Image(11: r3+10 , c1+c2+31:c1+c2+ c3 +30 ) = I3;
% Second Row
BG_Image(maxRows1 + 21: maxRows1 + r4 + 20, 11:c4+10) = I4;
BG_Image(maxRows1 + 21: maxRows1 + r5 + 20, c4 + 21 :c4 + c5+ 20) = I5;
figure, imshow(BG_Image);
I don't know why you want to do this but good luck !!

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!