首页 > 解决方案 > 将 2 个图像合并为一个平面图像

问题描述

我有两个单独的灰度图像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)

出去

标签: matlabimage-processingmatrixoverlayspectrogram

解决方案


您可以“手动”执行此操作:

  • 用于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);

结果:
在此处输入图像描述


推荐阅读