Place one image on a blank image but several times i.e (passport style)
조회 수: 1 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (4개)
pfb
2015년 4월 11일
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.
댓글 수: 0
Star Strider
2015년 4월 11일
댓글 수: 1
Image Analyst
2015년 4월 11일
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.
Image Analyst
2015년 4월 11일
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
Image Analyst
2015년 4월 12일
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?
DGM
2022년 6월 22일
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1041255/image.png)
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1041260/image.png)
That's just a thought.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!