gpt4 book ai didi

matlab - 灰度共现特征与方程不匹配

转载 作者:太空宇宙 更新时间:2023-11-03 20:23:19 25 4
gpt4 key购买 nike

考虑一个简单的 glcm 矩阵。

glcm = [0 1 2 3;1 1 2 3;1 0 2 0;0 0 0 3]; 

使用 Matlab 的内置功能计算统计数据。

stats = graycoprops(glcm)

Contrast: 2.8947
Correlation: 0.0783
Energy: 0.1191
Homogeneity: 0.5658

现在,改为使用本页底部给出的这些方程的定义手动计算它们:https://www.mathworks.com/help/images/ref/graycoprops.html

contrast = 0;
energy = 0
for i = 1:4
for j = 1:4
contrast = contrast + glcm(i,j)*(i-j)^2;
energy = energy + glcm(i,j)^2;
end
end

给出:

contrast =

110


energy =

43

这是怎么回事?是否进行了某种类型的规范化?不是简单的除以元素个数就是16...

有什么想法吗?谢谢!

最佳答案

正如我在 my comment 中告诉过你的那样, documentation for graycoprops明确指出:

graycoprops normalizes the gray-level co-occurrence matrix (GLCM) so that the sum of its elements is equal to 1.

但是如果你想找到这个函数的内部工作原理,你能做的最好的事情就是深入研究函数代码本身,找出它是如何做的。最好通过逐步调试代码来完成此操作。

如果您在命令窗口中键入edit graycoprops,您可以访问该函数的源代码。

如果这样做,您将能够看到在第 84 行附近有一个 if 语句调用另一个名为 normalizeGLCM 的函数。最后一个函数位于同一个文件中,因此如果您向下滚动,在第 119 行附近,您可以找到它的工作原理:

function glcm = normalizeGLCM(glcm)

% Normalize glcm so that sum(glcm(:)) is one.
if any(glcm(:))
glcm = glcm ./ sum(glcm(:));
end

因此,从本质上讲,如果您将上述规范化添加到您的代码中,它将生成与 graycoprops 函数相同的结果:

glcm = [0 1 2 3;1 1 2 3;1 0 2 0;0 0 0 3]; 

stats = graycoprops(glcm)

glcm_norm = glcm ./ sum(glcm(:)); % <-- Normalize.

contrast = 0;
energy = 0;
for i = 1:4
for j = 1:4
contrast = contrast + glcm_norm(i,j)*(i-j)^2;
energy = energy + glcm_norm(i,j)^2;
end
end

比较graycoprops的结果:

>> stats

stats =

struct with fields:

Contrast: 2.8947
Correlation: 0.0783
Energy: 0.1191
Homogeneity: 0.5658

你的结果:

>> contrast

contrast =

2.8947

>> energy

energy =

0.1191

它们完美匹配。

关于matlab - 灰度共现特征与方程不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47721768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com