![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/923554/image.png)
How can I stack images from multiple folders?
4 ビュー (過去 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/923399/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/923404/image.png)
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/923554/image.png)
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!