Align & Distribute Multiple images in An image

4 次查看(过去 30 天)
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

回答(1 个)

Gopichandh Danala
Gopichandh Danala 2017-6-26
编辑:Gopichandh Danala 2017-6-26
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 !!

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by