转 灰度共生矩阵(GLCM)并计算能量、熵、惯性矩、相关性(matlab)(待总结)
2016年11月27日 18:24:50
zoukangdlut
阅读数:3899
关于灰度共生矩阵的介绍可参考
http://blog.csdn.net/chuminnan2010/article/details/22035751
http://blog.csdn.net/xuezhisd/article/details/8908824
http://blog.csdn.net/xuexiang0704/article/details/8713204
http://cn.mathworks.com/help/images/ref/imlincomb.html?refresh=true
理论介绍
http://blog.csdn.net/lskyne/article/details/8659225 http://blog.csdn.net/light_lj/article/details/26098815 http://blog.csdn.net/kezunhai/article/details/42001477
共生矩阵的物理意义 http://blog.csdn.net/light_lj/article/details/26098815
下面给出不同的NumLevels的例子
-
-
-
-
-
GLCM = graycomatrix(gray,'GrayLimits',[])
-
-
-
-
-
-
-
-
-
-
-
-
-
-
GLCM = graycomatrix(gray, 'GrayLimits',[],'offset', [0 1])
-
-
-
-
-
-
-
-
-
-
-
-
-
GLCM = graycomatrix(gray, 'GrayLimits',[],'offset', [0 1],'NumLevels',8)
-
-
-
-
-
-
-
-
-
-
-
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
上图显示了如何求解灰度共生矩阵,以(1,1)点为例,GLCM(1,1)值为1说明只有一对灰度为1的像素水平相邻。GLCM(1,2)值为2,是因为有两对灰度为1和2的像素水平相邻。(1,5)出现一次,所以在(1.5)位置上标记1,没出现(1,6)所以为0;
上面所有的参数都是默认设置,NumLevels=8, 下面考虑NumLevels=3 的情况
-
-
-
-
-
-
-
-
-
-
-
slope = NumLevels/(GL(2) - GL(1));
-
intercept = 1 - (slope*(GL(1)));
-
SI = floor(imlincomb(slope,gray,intercept,'double'));
-
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-
-
-
-
-
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-
-
SI(SI > NumLevels) = NumLevels;
-
-
-
-
-
-
-
-
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
上面给出了如何将初始矩阵gray变成3阶的灰度级,SI就是gray的3阶灰度级矩阵。
上图显示了如何求解3级灰度共生矩阵,以(1,1)点为例,GLCM(1,1)值为4说明只有4对灰度为1的像素水平相邻。GLCM(3,1)值为2,是因为有两对灰度为3和1的像素水平相邻。(2,1)出现一次,所以在(2.1)位置上标记1,没出现(1,3)所以为0;
-
-
-
-
-
[GLCM,SI] = graycomatrix(gray,'NumLevels',3,'G',[])
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
用3阶灰度级去计算四个共生矩阵P,取距离为1,角度分别为0,45,90,135
-
-
-
-
-
offsets = [0 1;-1 1;-1 0;-1 -1];
-
-
[GLCMS,SI] = graycomatrix(gray,'GrayLimits',[],'Of',offsets,'NumLevels',m);
-
-
-
-
-
-
P(:,:,n) = P(:,:,n)/sum(sum(P(:,:,n)));
-
-
-
-
-
-
-
-
-
-
-
-
E(n) = sum(sum(P(:,:,n).^2));
-
-
-
-
H(n) = -P(i,j,n)*log(P(i,j,n))+H(n);
-
-
I(n) = (i-j)^2*P(i,j,n)+I(n);
-
-
Ux(n) = i*P(i,j,n)+Ux(n);
-
Uy(n) = j*P(i,j,n)+Uy(n);
-
-
-
-
-
-
-
deltaX(n) = (i-Ux(n))^2*P(i,j,n)+deltaX(n);
-
deltaY(n) = (j-Uy(n))^2*P(i,j,n)+deltaY(n);
-
C(n) = i*j*P(i,j,n)+C(n);
-
-
-
C(n) = (C(n)-Ux(n)*Uy(n))/deltaX(n)/deltaY(n);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
sprintf('0,45,90,135方向上的能量依次为: %f, %f, %f, %f',E(1),E(2),E(3),E(4))
-
sprintf('0,45,90,135方向上的熵依次为: %f, %f, %f, %f',H(1),H(2),H(3),H(4))
-
sprintf('0,45,90,135方向上的惯性矩依次为: %f, %f, %f, %f',I(1),I(2),I(3),I(4))
-
sprintf('0,45,90,135方向上的相关性依次为: %f, %f, %f, %f',C(1),C(2),C(3),C(4))
-
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
下面给出的是默认的设置下求四个方向的灰度共生矩阵,NumLevels=8.
-
-
-
-
-
offsets = [0 1;-1 1;-1 0;-1 <
|
请发表评论