
How can I stack images from multiple folders?
2 次查看(过去 30 天)
显示 更早的评论
I got three images in three diffrent folders attached(1, Background. 2,Body 3, Expressions). I help stacking the images together from attached three diffrent folders. i would appreciate any help with the code.
imfuse will work to combine the imgaes from single folder. But, i need help pick the images from diffrent folders and stack it together as shwon here.


0 个评论
采纳的回答
DGM
2022-3-11
编辑:DGM
2022-3-11
As far as I know, nothing in MATLAB or IPT directly supports images with alpha, though you can certainly tote alpha around as a separate mask image. Even at that, imfuse() isn't a composition tool and has no means to utilize a mask.
% read images and alpha
[expr,~,expra] = imread('Expressions/standard.png');
[body,~,bodya] = imread('Body/maroon.png');
BG = imread('Background/blue.png');
% convert to floating point for simplicity
expr = im2double(expr);
expra = im2double(expra);
body = im2double(body);
bodya = im2double(bodya);
BG = im2double(BG);
% compose the image as weighted sums, working from the bottom up
outpict = body.*bodya + BG.*(1-bodya);
outpict = expr.*expra + outpict.*(1-expra);
% convert back to original class
outpict = im2uint8(outpict);
imshow(outpict)

MIMT has tools that can do this more succinctly, either using the alpha as a separate mask:
[expr,~,expra] = imread('Expressions/standard.png');
[body,~,bodya] = imread('Body/maroon.png');
BG = imread('Background/blue.png');
outpict = replacepixels(body,BG,bodya);
outpict = replacepixels(expr,outpict,expra);
imshow(outpict)
... or by using alpha combined with the image (RGBA)
[expr,~,expra] = imread('Expressions/standard.png');
[body,~,bodya] = imread('Body/maroon.png');
BG = imread('Background/blue.png');
% these are now RGBA images
expr = cat(3,expr,expra);
body = cat(3,body,bodya);
% imblend and imshow2 handle RGBA images just fine
outpict = imblend(body,BG,1,'normal');
outpict = imblend(expr,outpict,1,'normal');
imshow2(outpict)
... or the images can be combined as a layer stack and composed in a single pass:
[expr,~,expra] = imread('Expressions/standard.png');
[body,~,bodya] = imread('Body/maroon.png');
BG = imread('Background/blue.png');
% these are now RGBA images
expr = cat(3,expr,expra);
body = cat(3,body,bodya);
% pad and stack on dim4
stack = imstacker({expr,body,BG});
% compose the entire stack in one shot
outpict = mergedown(stack,1,'normal');
imshow2(outpict)
Though the latter two cases only makes sense if an RGBA workflow is convenient for other reasons. As I said, nothing in MATLAB or IPT knows what to do with an RGBA image, so you'd constantly have to work around that.
15 个评论
DGM
2022-3-14
I'm not going to be much help with that, since the video encoding tools don't work in my environment. There are some examples in the documentation, and Image Analyst has posted a similar demo before:
The general workflow would be
Generate image sequence -> Convert image sequence to video
更多回答(1 个)
Benjamin Thompson
2022-3-11
montage or imtile should work for what you want.
1 个评论
DGM
2022-3-11
Neither imfuse(), montage(), nor imtile() support RGBA images or RGB images with a mask of any form.
Despite the wording of the documentation, I don't think it's reasonable to call these composition tools. The closest that any of these come to image composition is imfuse() with a 'blend' option, but that's only supported for I/RGB images, and it only supports 50% opacity with no mask. It's more of a crude comparison tool than anything.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!