Place one image on a blank image but several times i.e (passport style)

3 views (last 30 days)
I have an image variable 'AdjustedImage' and a blank paper created in Photoshop (3000x2000 px) read into MATLAB as 'BPaper'.
I want to be able to put the image on the BPaper several times, like seen in Passport booth prints. I have specific rows and columns for each image size. i.e. 45x35mm = Row value 2, Column value 4. I was thinking of a subplot (table) on top of the image, but couldn't understand how to code it. The gaps would have to be equal too.
Any suggestions?
Thanks.

Answers (4)

pfb
pfb on 11 Apr 2015
Hi,
you can try the command axes('position',p), where p is a vector specifying the position in the figure. You can create a "large" axis for the background, and many small ones on top of it for the photos. You'll have to fiddle with units and aspect ratios to get it right, though.

Star Strider
Star Strider on 11 Apr 2015
Consider the Image Processing Toolbox montage function.
  1 Comment
Image Analyst
Image Analyst on 11 Apr 2015
montage() stitches images together but does not allow a "contact sheet" type of photo where the background paper image underlies the other images and shows through between them.

Sign in to comment.


Image Analyst
Image Analyst on 11 Apr 2015
To paste the images onto the paper background image, you need to copy and paste your image, like I show in my attached demo. It's simple, but let me know if you can't figure out how to adapt it. Basically you just assign the image you want to paste in a rectangular region of the same size of the background image
backgroundImage(r1:r2, c1:c2) = otherImage;
  2 Comments
Image Analyst
Image Analyst on 12 Apr 2015
Right. With montage, the background image would just be stitched in there like any other image in the array. Why don't you show us your resulting image? So you've saved the image into a variable. Of course you can copy it, but copy it where? To another variable? To an image format file on disk? To a displayed figure?

Sign in to comment.


DGM
DGM on 22 Jun 2022
If the FG images are simple, solid rectangular images, you can just write a loop and insert each image into the background by direct addressing as shown prior. This can be limited, depending on the effect that's intended.
I doubt anyone will ever see this on a low-traffic question, but I'll offer it anyway. This is how I'd do it. As usual, this makes heavy use of MIMT tools to simplify the task. This isn't necessarily computationally-efficient, but it's easier to write and the RGBA workflow means that it has some extra flexibility.
% read background image
BG = imread('sources/crumpledpaper.jpg');
BG = imresize(BG,0.15); % don't need it to be so large for a demo
% read multiple FG images into a cell array
fgstack = mimread('cmanface/cmanface_*.png');
% stack images on dim4, padding as necessary
fgstack = imstacker(fgstack); % defaults include transparent padding
szb = imsize(BG,2); % bg page size
szf = imsize(fgstack,2); % fg page size
tiling = [3 5]; % choose a tiling that can hold the given number of frames
% calculate padding for even distribution of frames on BG
szpadded = floor(szb./tiling);
padamt = szpadded-szf;
padamt = reshape([floor(padamt/2); ceil(padamt/2)],1,4);
% pad all FG frames simultaneously
fgstack = addborder(fgstack,padamt,[0 0]); % padding is [0 0], i.e. transparent black
% tile FG frames into a single RGBA frame
FG = imtile(fgstack,tiling);
% restack FG and BG, simultaneously centering and padding to match geometry
outpict = imstacker({FG BG});
% composite FG,BG to form a single image
outpict = mergedown(outpict,1,'normal');
outpict = splitalpha(outpict); % strip extraneous alpha channel
imshow(outpict)
No loops are needed, and the images are automatically padded and centered, even if they aren't the same size. The images don't even have to be rectangular solid images. They can be transparent to begin with.
% read background image
BG = imread('sources/crumpledpaper.jpg');
BG = imresize(BG,0.23); % don't need it to be so large for a demo
% read multiple FG images into a cell array
fgstack = mimread('forum_dump/answers_forum/cartoon_parts/bodyhuesweep1/character_*.png');
% maybe rotate a few of the images to show that RGBA workflow has conveniences
% both color and alpha are zero-padded when rotating, so there's no black padding to deal with
% this also demonstrates that the images don't have to be the same size
fgstack{2} = imrotate(fgstack{2},5);
fgstack{9} = imrotate(fgstack{9},-5);
fgstack{13} = imrotate(fgstack{13},85);
% stack images on dim4, padding as necessary
fgstack = imstacker(fgstack); % defaults include transparent padding
fgstack = imresize(fgstack,0.25); % again, don't need it to be huge for this demo
szb = imsize(BG,2); % bg page size
szf = imsize(fgstack,2); % fg page size
tiling = [3 5]; % choose a tiling that can hold the given number of frames
% calculate padding for even distribution of frames on BG
szpadded = floor(szb./tiling);
padamt = szpadded-szf;
padamt = reshape([floor(padamt/2); ceil(padamt/2)],1,4)
% pad all FG frames simultaneously
fgstack = addborder(fgstack,padamt,[0 0]); % padding is [0 0], i.e. transparent black
% tile FG frames into a single RGBA frame
FG = imtile(fgstack,tiling);
% restack FG and BG, simultaneously centering and padding to match geometry
outpict = imstacker({FG BG});
% composite FG,BG to form a single image
outpict = mergedown(outpict,1,'normal');
outpict = splitalpha(outpict); % strip extraneous alpha channel
imshow(outpict)
That's just a thought.

Community Treasure Hunt

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

Start Hunting!