灰度共生矩阵的相关性
相关性(Correlation)
公式
Correlation = ∑ i = 1 N g ∑ j = 1 N g ( i − μ x ) ( j − μ y ) P ( i , j ) σ x σ y \text{Correlation} = \frac{\sum_{i=1}^{N_g} \sum_{j=1}^{N_g} (i - \mu_x)(j - \mu_y) P(i,j)}{\sigma_x \sigma_y} Correlation=σxσy∑i=1Ng∑j=1Ng(i−μx)(j−μy)P(i,j)
计算步骤
-
计算每个灰度级别的边缘概率:
- 行边缘概率
p
x
(
i
)
p_x(i)
px(i):
p x ( i ) = ∑ j = 1 N g P ( i , j ) p_x(i) = \sum_{j=1}^{N_g} P(i,j) px(i)=j=1∑NgP(i,j) - 列边缘概率
p
y
(
j
)
p_y(j)
py(j):
p y ( j ) = ∑ i = 1 N g P ( i , j ) p_y(j) = \sum_{i=1}^{N_g} P(i,j) py(j)=i=1∑NgP(i,j)
- 行边缘概率
p
x
(
i
)
p_x(i)
px(i):
-
计算均值:
- 行均值
μ
x
\mu_x
μx:
μ x = ∑ i = 1 N g i ⋅ p x ( i ) \mu_x = \sum_{i=1}^{N_g} i \cdot p_x(i) μx=i=1∑Ngi⋅px(i) - 列均值
μ
y
\mu_y
μy:
μ y = ∑ j = 1 N g j ⋅ p y ( j ) \mu_y = \sum_{j=1}^{N_g} j \cdot p_y(j) μy=j=1∑Ngj⋅py(j)
- 行均值
μ
x
\mu_x
μx:
-
计算标准差:
- 行标准差
σ
x
\sigma_x
σx:
σ x = ∑ i = 1 N g ( i − μ x ) 2 ⋅ p x ( i ) \sigma_x = \sqrt{\sum_{i=1}^{N_g} (i - \mu_x)^2 \cdot p_x(i)} σx=i=1∑Ng(i−μx)2⋅px(i) - 列标准差
σ
y
\sigma_y
σy:
σ y = ∑ j = 1 N g ( j − μ y ) 2 ⋅ p y ( j ) \sigma_y = \sqrt{\sum_{j=1}^{N_g} (j - \mu_y)^2 \cdot p_y(j)} σy=j=1∑Ng(j−μy)2⋅py(j)
- 行标准差
σ
x
\sigma_x
σx:
-
计算协方差:
Cov ( i , j ) = ∑ i = 1 N g ∑ j = 1 N g ( i − μ x ) ( j − μ y ) P ( i , j ) \text{Cov}(i, j) = \sum_{i=1}^{N_g} \sum_{j=1}^{N_g} (i - \mu_x)(j - \mu_y) P(i,j) Cov(i,j)=i=1∑Ngj=1∑Ng(i−μx)(j−μy)P(i,j) -
计算相关性:
Correlation = Cov ( i , j ) σ x σ y \text{Correlation} = \frac{\text{Cov}(i, j)}{\sigma_x \sigma_y} Correlation=σxσyCov(i,j)
%%
filename = 'board';
circuitBoard = rot90(im2gray(imread([filename,'.tif'])));
figure, imshow(circuitBoard), title('Circuit Board Image')
%%
offsets0 = [zeros(40,1) (1:40)'];
%% Create the GLCMs. Call the graycomatrix function specifying the offsets.
glcms = graycomatrix(circuitBoard,'Offset',offsets0,'NumLevels',64);
%%
figure, montage(mat2gray(log(1+glcms)), 'Size', [5 8])
colormap(jet), title('Gray-Level Co-Occurrence Matrices')
%%
stats = graycoprops(glcms,'Correlation');
%%
%Plot correlation as a function of offset.
figure, plot([stats.Correlation], 'LineWidth',1);
xlabel('Horizontal Offset')
ylabel('Correlation')
title('Texture Correlation as A Function of Offset');
禹晶、肖创柏、廖庆敏《数字图像处理(面向新工科的电工电子信息基础课程系列教材)》
禹晶、肖创柏、廖庆敏《数字图像处理》资源二维码