我正在尝试在 matlab 中组合图像数量。组合图像的数量最多为四个。我希望它们根据图层的概念(如在 Photoshop 中)进行组合,而不是连接在一起。这意味着结果图像的大小将与每个组合图像的大小相同。是否有一个 matlab 函数可以正确完成该任务?
问问题
4526 次
2 回答
0
尝试这个:
img1 = imread...
img2 = imread...
img3 = imread...
img4 = imread...
combined_img(:,1) = img1;
combined_img(:,2) = img2;
combined_img(:,3) = img3;
combined_img(:,4) = img4;
现在您有一个 4 层图像,您可以通过 combine_img 的第三个索引访问它。以下命令将显示第一张图片:
imshow(combined_img(:,1));
于 2012-08-27T06:38:54.273 回答
0
这就像你描述的那样:
function imgLayers
% initialize figure
figure(1), clf, hold on
% just some random image (included with Matlab) to server
% as the background
img{1,1} = imresize(imread('westconcordaerial.png'), 4);
img{1,2} = [0 0];
% rotate the image and discolor it to create another image
img{2,1} = uint8(imresize(imrotate(img{1}, +12), 0.3)/2.5);
img{2,2} = [150 20];
% and another image
img{3,1} = uint8(imresize(imrotate(img{1}, -15), 0.5)*2.5);
img{3,2} = [450 80];
% show the stacked image
imshow(stack_image(img));
%% create new image, based on several layers
function newImg = stack_image(imgs)
% every image contained at a cell index (ii) is placed
% on top of all the previous ones (0:ii-1)
rows = cellfun(@(x)size(x,1),imgs(:,1));
cols = cellfun(@(x)size(x,2),imgs(:,1));
% initialize new image
newImg = zeros(max(rows(:)), max(cols(:)), 3, 'uint8');
% traverse the stack
for ii = 1:size(imgs,1)
layer = imgs{ii,1};
offset = imgs{ii,2};
newImg( offset(1)+(1:rows(ii)), offset(2)+(1:cols(ii)), :) = layer;
end
end
end
不过要小心——没有足够的绑定检查等。所以你必须做一些自己的发展。但这应该足以让你开始:)
于 2012-08-27T13:17:47.483 回答