mat2gray对多阈值的影响
Effect of mat2gray on multithresh
我不明白为什么在 "original" 双像上使用 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);
在这里,在我的例子中,l1
与 l0
的区别在于 808 像素。为什么? testimage
和 mat2gray(testimage)
中像素的相对差异应该是相等的,只是绝对差异发生了变化。这对 multithresh 有多重要?
您间接 运行 陷入浮动精度错误。如果我们稍微修改一下您的代码,只是为了可视化它
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 why、imquantize
必须将图像的值与 >=
或阈值进行比较类似的,它会在一种情况下通过而在另一种情况下会失败。
遗憾的是,我找不到修改代码以确保 l0
和 l1
在每种情况下都相等的简单方法。
我不明白为什么在 "original" 双像上使用 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);
在这里,在我的例子中,l1
与 l0
的区别在于 808 像素。为什么? testimage
和 mat2gray(testimage)
中像素的相对差异应该是相等的,只是绝对差异发生了变化。这对 multithresh 有多重要?
您间接 运行 陷入浮动精度错误。如果我们稍微修改一下您的代码,只是为了可视化它
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 why、imquantize
必须将图像的值与 >=
或阈值进行比较类似的,它会在一种情况下通过而在另一种情况下会失败。
遗憾的是,我找不到修改代码以确保 l0
和 l1
在每种情况下都相等的简单方法。