【问题标题】:How can I merge multiple images into one and save it on matlab?如何将多张图像合并为一张并保存在matlab上?
【发布时间】:2019-10-30 22:58:23
【问题描述】:

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

我尝试了多个代码,但实际上我无法理解它。我想要实现的是叠加两个图像的透明覆盖(不确定),您实际上可以看到两个图像

figure1 = figure;
ax1 = axes('Parent',figure1);
ax2 = axes('Parent',figure1);
set(ax1,'Visible','off');
set(ax2,'Visible','off');
[a,map,alpha] = imread('E:\training data\0.bmp');
I = imshow(a,'Parent',ax2);
set(I,'AlphaData',alpha);
F = imshow('E:\training data\200.bmp','Parent',ax1);

我只想叠加多张图片。

这是我的数据集:

这是我想要实现的,我想将所有旋转的图像添加到一个中

这就是我得到的遗憾,我已经尝试了一切

【问题讨论】:

  • 您能否添加一些您想要合并的图像的示例以阐明您想要实现的目标?
  • 我已经添加了上面的图片,请参考,蓝色的文字带有每个标题的下划线

标签: matlab image-processing


【解决方案1】:

以下内容可以满足您的需求。首先加载图像,然后将其分成 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)

【讨论】:

    猜你喜欢
    • 2013-07-18
    • 2012-03-04
    • 2017-12-25
    • 1970-01-01
    • 2022-07-01
    • 2016-03-31
    • 2012-07-29
    • 1970-01-01
    相关资源
    最近更新 更多