简体   繁体   中英

How can I merge multiple images into one and save it on matlab?

I need to merge multiple bitmap of same sizes into one image.That image is basically rotated in different angles and needs to be merged into one whole image. I have tried multiple methods but I come with many issues as I am not able to save that image.

I have tried multiple codes but I actually cannot make sense out of it. What I want to achieve is transparent overlay (not sure) that superimposes two images and you can actually see both one image

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);

I just want to superimpose multiple images.

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

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

The following does kind of what you want. First load the image, then divide it into 6 equal blocks, and add these. To add the pixel values, I first converted the image to doubles, since uint8 only can go up to pixel values of 255. This would mean that you will just see a large bright spot in the image because you are clipping.

Then add all the blocks. You will see in the output, that the car is not always perfect in the center of the block, so depending on what you are trying to achieve you may want to align the blocks using something like 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM