如何将多张图像合并为一张图像并将其保存在matlab上?

时间:2019-10-29 07:10:59

标签: matlab image-processing

我需要将多个相同大小的位图合并到一个图像中,该图像基本上以不同的角度旋转,并且需要合并为一个完整的图像。我尝试了多种方法,但由于无法保存该图像,因此遇到了许多问题。

我尝试了多种代码,但实际上我没有任何意义。我想要实现的是透明叠加层(不确定),该叠加层可以叠加两张图片,您实际上可以看到一张图片

setTimeout

我只想叠加多张图像。

这是我的数据集:

This is my data set

这是我想要实现的,我想将所有旋转后的图像添加并实现为一个 This is what I want to achieve, i want to add all of the rotated images and achieved into one

这就是我很难过的,我已经尝试了一切

This is what I get sadly, I have tried everything

1 个答案:

答案 0 :(得分:0)

以下内容确实满足您的需求。首先加载图像,然后将其划分为6个相等的块,并将其相加。为了添加像素值,我首先将图像转换为两倍,因为uint8最多只能达到255的像素值。这意味着由于剪切,您只会在图像中看到很大的亮点。

然后添加所有块。您将在输出中看到,汽车不一定总是位于方块中心,因此根据您要实现的目标,您可能需要使用xcorr2之类的东西来对齐方块。

% load image
A = imread('S82CW.jpg');

fig = figure(1); clf
image(A);

% convert A to double and divide in blocks. 
A = double(A);
[img_h, img_w, ~] = size(A);

block_h = img_h/2;
block_w = img_w/3;

% split image in blocks
Asplit = mat2cell(A, repelem(block_h,2), repelem(block_w,3), 3);

% check if splitting makes sense
figure(2); clf
for k = 1:numel(Asplit)
    subplot(3,2,k)
    image(uint8(Asplit{k}))
end

% superimpose  all blocks, 
A_super = zeros(size(Asplit{1,1}),'like',Asplit{1,1} ); % init array, make sure same datatype
for k = 1:numel(Asplit)
    A_super = A_super + Asplit{k};
end
% divide by max value in A and multiply by 255 to make pixel 
%   values fit in uint8 (0-255)
A_super_unit8 = uint8(A_super/max(A_super,[],'all')*255);

figure(3); clf;
image(A_super_unit8)