matlab - 将 2 个图像合并为一个平面图像
问题描述
我有两个单独的灰度图像im1
(图 1)和im2
(图 2),每个大小为 50 x 50,通过颜色编码显示在这里。当我使用命令将它们组合在一起cat()
然后显示连接图像的结果时,它们会并排显示(图3)。但是,如果我通过复制第二个图像中的第一个来创建第三个图像,然后显示这 3 个图像的连接,我会得到一个图像(图 4)。我不明白RGB(3维)的合并是如何可能的,而转换为灰度的合并没有发生。如何使用这两个图像获得单个图像im1
并im2
合并或覆盖在法律上可行且不能并排的图像?我如何叠加im1
和im2
获取单个图像并通过颜色编码显示它?
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)
解决方案
您可以“手动”执行此操作:
- 用于
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);
推荐阅读
- javascript - 如何为 react-router Link 的执行 onClick 功能设置超时?
- jquery - 从标签中获取内容
- c - 使用 -std=c11 标志编译部分代码
- php - haveRaw 不能在 laravel 的分页中工作
- chef-infra - 检查厨师食谱中是否存在文件/目录的最简洁方法是什么?
- python - 将表单添加到 Dash/Plotly 应用程序
- javascript - 获取每次添加的新数据的 id
- python - 如何使用 FacetGrid 显示一些选定的行
- autodesk-forge - Autodesk Forge Viewer three.min.js 找不到错误
- mod-rewrite - 反向代理的虚拟主机中的 mod_rewrite