【问题标题】:How to display error map of two binary images by matlabmatlab如何显示两个二值图像的误差图
【发布时间】:2014-04-02 00:31:54
【问题描述】:

我有两个二值图像,分别是真实图像 A 和测试图像 B。我想计算骰子系数相似度 defined here。 计算它非常容易。这是一个相同的代码

function dist = dist_Dice(A,B)
    % Calculation of the Dice Coefficient

    idx_img = find(B== 1);
    idx_ref = find(A== 1);
    idx_inter = find((B== 1) & (A== 1));

    dist = 2*length(idx_inter)/(length(idx_ref)+length(idx_img));

结果是一个数字。但我的工作是如何通过图像直观地展示这个结果。图像的范围从 0 到 1。我不知道如何解决它?我认为它类似于区域重叠的两个图像的重叠,像素等于 0,否则等于 1。你能帮我在 matlab 中实现吗?

【问题讨论】:

  • A 和 B 是二值图像?
  • 是的,先生。两个图像都是二进制的

标签: image image-processing matlab matlab-figure


【解决方案1】:

我不知道在可视化差异方面,这样的事情是否接近您的想法。正如您所指出的,您感兴趣的数量是一个标量,因此没有太多选择。

RandStream.setDefaultStream(RandStream('mt19937ar','seed',0)); % For reproducibility of results

a = rand(10);
b = rand(10);

A = im2bw(a, graythresh(a));
subplot(2,2,1)
imshow(A, 'InitialMagnification', 'fit')
title('A (ground truth image)')

B = im2bw(b, graythresh(b));
subplot(2,2,2)
imshow(B, 'InitialMagnification', 'fit')
title('B (test image)')

idx_img = find(B);
idx_ref = find(A);
idx_inter = find(A&B);

common_white = zeros(size(A));
common_white(idx_inter) = 1;

subplot(2,2,3)
imshow(common_white, 'InitialMagnification', 'fit')
title('White in both pictures')

dist = 2*length(idx_inter)/(length(idx_ref)+length(idx_img))

idx_img = find(~B);
idx_ref = find(~A);
idx_inter = find(~A&~B);

common_black = ones(size(A));
common_black(idx_inter) = 0;

subplot(2,2,4)
imshow(common_black, 'InitialMagnification', 'fit')
title('Black in both pictures')

dist = 2*length(idx_inter)/(length(idx_ref)+length(idx_img))

【讨论】:

    【解决方案2】:

    认为你正在寻找这个 -

    AB = false(size(A));
    AB(idx_inter) = true;
    figure, imshow(AB)
    

    【讨论】:

      【解决方案3】:

      通常,对于二进制图像,请注意您不必执行 ==1 部分。另外,如果您只需要知道图像中有多少个,则无需使用findlength,您可以在二进制图像上使用sum

      AB = A&B
      imshow(AB);
      
      dist = 2*sum(AB(:))/(sum(A(:))+sum(B(:)));
      

      find(抱歉,无法抗拒)m = find(A) 用于 256 x 256 图像,大约是 ==1 等效图像的​​两倍。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-22
        • 1970-01-01
        • 2016-05-29
        • 1970-01-01
        • 2018-01-06
        • 1970-01-01
        • 2017-02-20
        • 2012-06-01
        相关资源
        最近更新 更多