将2张图像合并为一个平面图像

时间:2020-02-13 17:37:51

标签: matlab image-processing matrix overlay spectrogram

我有两个单独的灰度图像im1(图1)和im2(图2),每个图像的大小为50 x 50,并通过颜色编码在此处显示。当我使用cat()命令将它们组合在一起,然后显示级联图像的结果时,它们并排显示(图3)。但是,如果我通过复制第二张图像中的第一张来创建第三张图像,然后显示3张图像的串联,则会得到一张图像(图4)。我不知道如何合并RGB(3个维度),而将其转换为灰度则不会发生。如何使用合并或叠加的两个图像im1im2来获得单个图像,这在法律上是可能的并且不能并排?我如何重叠im1im2以获得单个图像并通过颜色编码显示它?

imgGray = cat(2,im1,im2);
imshow(imgGray)
imgGray = cat(2,im1,im2);  
imshow(imgGray)
imagesc(imgGray)
im3=im1;
imgColor = cat(3,im1,im2,im3);  
imagesc(imgColor)

out

2 个答案:

答案 0 :(得分:1)

您可以“手动”进行操作:

  • 使用ind2rgb通过“颜色编码”将每个灰度图像转换为RGB。
  • 计算两个RGB图像的平均值以获得“融合图像”。

这是一个代码示例:

% Use cameraman as first image, and resized moon for the second image (just for example).
I1 = imread('cameraman.tif'); % I1 is uint8 Grayscale
I2 = imresize(imread('moon.tif'), size(I1));  % I2 is uint8 Grayscale

% Convert images to RGB using parula color map (you may choose any color map).
J1 = ind2rgb(I1, parula(256)); % J1 is double RGB (three color planes in range [0, 1]).
J2 = ind2rgb(I2, parula(256)); % J2 is double RGB (three color planes in range [0, 1]).

% Fuse J1 and J2 "manually".
alpah = 0.5; % Using alpah=0.5, gives average of J1 and J2.
K = J1*alpah + J2*(1-alpah); %K is is double RGB.
K = im2uint8(K); % Convert K to uint8 (im2uint8 multiplies pixels by 255, and convert to uint8).

%Display result
figure;imshow(K);

结果:
enter image description here

答案 1 :(得分:1)

您还可以将它们彼此添加(在对它们进行规范化后 ),并用单个颜色图表示所有情况

imagesc(I1+I2);

enter image description here

或者如果您想根据颜色和强度设置透明度,可以添加

alpha color
alpha scaled