【问题标题】:How to superimpose more than one image figure in a single figure using MATLAB?如何使用 MATLAB 在单个图形中叠加多个图像图形?
【发布时间】:2018-09-23 11:23:40
【问题描述】:

基于这个想法(图) 我试图将所有这三个输出(边缘)绘制在一个图像中,用不同的颜色来表示每个输出(而不是像 subplot 或 imshowpair 之类的东西)。现在我的输出只是三个不同的图像。

clear all
close all
clc
%% ground truth
img = imread('22o.jpg');
img_gray = rgb2gray(img);
img_ground_truth = imread('22g.jpg');
img_ground_truth = im2bw(img_ground_truth);
cc = img_ground_truth;
%cc = img_ground_truth(11:54, 112:171);

%% Detected part
img_edge = edge(img_gray, 'canny');
dd = img_edge;
%dd = img_edge(11:54, 112:171);

%% True pixel, false pixel, true negative 
[m n] = size(cc);
true_pixel = zeros(m,n);
false_pixel = zeros(m,n);
false_negative = zeros(m,n);
for i = 1:m
    for j = 1:n
        if (dd(i,j) == cc(i,j))
            true_pixel(i,j) = dd(i,j);          

        elseif (dd(i,j)~= cc(i,j))
            false_pixel(i,j) = dd(i,j);
        end
    end
end
for i = 1:m
    for j = 1:n
        if (cc(i,j)==1 && dd(i,j)==0)
            false_negative(i,j) = cc(i,j);
        end
    end
end
% subplot(2,3,1); imshow(cc); title('Gt');
% subplot(2,3,2); imshow(dd); title('Dc');
figure(1),imshow(true_pixel, 'ColorMap',[1 1 1;0 1 0]); 
title('True Pixel (TP)');
hold on
figure(2),imshow(false_pixel, 'ColorMap',[1 1 1;1 0 0]); 
title('False Pixel (FP)');
hold on
figure(3),imshow(false_negative, 'ColorMap',[1 1 1;0 0 1]); 
title('False Negative (FN)');
hold off

【问题讨论】:

  • “不像 subplot”——但 subplot 正是你想在这里使用的。你试过吗?
  • 不,我希望将这三个边缘都加到一张图像上,这样我们就可以在一张图像中看到所有这三个彩色边缘。虽然会有一些重叠,但没关系。
  • 在图中显示了 3 个子图。如果你想重新创建它,你需要subplot
  • 如果你有“假阴性”,那么其他标签很有可能是“真阳性”和“假阳性”,而不是“真像素”
  • 你是问如何将3张图片合并为一张,比如merged_image = cat(3, false_pixel, true_pixel, false_negative)

标签: matlab edge-detection imshow


【解决方案1】:

我在 cmets 中建议的原始解决方案是:

merged_image = cat(3, false_pixel, true_pixel, false_negative);
imshow(merged_image)

这会导致真负像素为黑色的图像:

(请原谅最上面的图例,我用了你的图,懒得删了。)

如果三个图像之间有任何重叠的可能性,我会使用这种方法。如果您希望 TN 为白色,而不是将像素添加到所需通道,您可以从其他两个通道中减去它们:

% turn images into logical arrays to use in indexing
true_pixel = logical(true_pixel);
false_pixel = logical(false_pixel);
false_negative = logical(false_negative);

% create RGB channels for all-white image
r_channel = ones(size(true_pixel));
g_channel = ones(size(true_pixel));
b_channel = ones(size(true_pixel));

% leave pixels in true_pixel image green
r_channel(true_pixel) = 0;
b_channel(true_pixel) = 0;

% leave pixels in false_pixel image red 
g_channel(false_pixel) = 0;
b_channel(false_pixel) = 0;

% leave pixels in false_negative image blue
r_channel(false_negative) = 0;
g_channel(false_negative) = 0;

% merge into RGB image 
merged_image = cat(3, r_channel, g_channel, b_channel);
imshow(merged_image)

结果:

另一种可能性是像最初那样使用索引图像。最干净的方法是在循环内的合并图像中生成不同的索引{1,2,3},所以在最后一个循环中是这样的(以及其他两个循环中的类似代码):

...
false_negative(i,j) = cc(i,j);
merged_image(i,j) = cc(i,j)*3; 
...

然后在最后,将所有 3 种颜色组合成一个颜色图:

imshow(uint8(merged_image), 'ColorMap', [1 1 1; 0 1 0; 1 0 0; 0 0 1])

【讨论】:

    猜你喜欢
    • 2018-12-25
    • 2016-07-05
    • 2012-03-14
    • 1970-01-01
    • 1970-01-01
    • 2015-08-30
    • 2011-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多