【问题标题】:Effect of mat2gray on multithreshmat2gray对multithresh的影响
【发布时间】:2016-11-06 08:37:59
【问题描述】:

我不明白为什么在“原始”双图像上使用multithresh 获得的分割与在同一图像上使用相同参数通过mat2gray 缩放的分割不同。

例如:

testimage = randi(100,[200 200]);
figure;imagesc(testimage)


threshs = multithresh(testimage,5);
l0 = imquantize(testimage,threshs);

threshs = multithresh(mat2gray(testimage),5);
l1 = imquantize(mat2gray(testimage),threshs);

在这里,在我的情况下,l1l0 不同,为 808 像素。为什么? testimagemat2gray(testimage) 中像素之间的相对差异应该是相等的,只是绝对差异发生了变化。这对 multithresh 有多重要?

【问题讨论】:

  • 我的猜测是范围为0-max(img)>1 的图像被视为0-255 图像,并且在multitresh 中有影响
  • @AnderBiguri:这到底是什么意思?值 > 255 会发生什么?当 testimage 是双倍时,这种行为也会出现,顺便说一句。另请注意,在我看来,当 testimage 为 float 类型时,它被缩放为 [0 1](参见 multithresh 的第 224 行)

标签: matlab image-processing cluster-analysis image-segmentation


【解决方案1】:

您间接遇到了浮点精度错误。如果我们稍微修改一下你的代码,只是为了可视化它

testimage = randi(100,[200 200]);
figure;imagesc(testimage)

gray_image=mat2gray(testimage);

threshs1 = multithresh(testimage,5);
l0 = imquantize(testimage,threshs1);

threshs2 = multithresh(gray_image,5);
l1 = imquantize(gray_image,threshs2);

%For this example
threshs1
%threshs1 =
%       17.6941    34.0000    50.6941    67.0000    83.6941

threshs2
%threshs2 =
%        0.1686     0.3333     0.5020     0.6667     0.8353

然后我们在两个原始矩阵中找到差异点之一

find(l0~=l1,1)
%ans =
%    67

testimage(67)
%ans =
%    34

gray_image(67)
%ans =
%    0.3333

这就是浮动精度发挥作用的地方

testimage(67)==threshs1(2)  % 34 == 34.0000
%ans =
%     1

gray_image(67)==threshs2(2) % 0.3333 == 0.3333
%ans =
%     0

1/3 的值未正确保存为二进制,see here for an explanation whyimquantize 必须将图像的值与具有>= 或类似值的阈值进行比较,并且在一种情况下它会通过并且另一个失败。

遗憾的是,我看不到一种简单的方法来修改您的代码以确保 l0l1 在每种情况下都相等。

【讨论】:

  • 很有趣,感谢您的回答!现在我想知道为什么 thresh2 首先不是 thresh1 ./ 100 ...
  • 我猜这与mat2graytestimagegray_image 的映射有关。 gray_image 也不是 testimage./100,所以我看不出阈值会是多少
  • 是的,没错,因为 testimage 中的最小值通常是 1(而不是 0!)。因此,threshs2 = (threshs1-1) / (100-1)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-18
  • 2012-06-12
  • 2020-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多