2016-08-30 57 views
-2

我尝试使用wikipedia中的公式实现GLCM方法,但由于matlab索引问题,我有问题来填充我的GLCM。灰度共生矩阵

我也使用NitdepthQuantisation来减少灰度级的数量,但现在我使用全8位。

function [C] = GLCM(img, level, theta, delta) 

% Quantisation of the input Image to desired value 
imgQ = ImageQuantisation(img, level); 
[m n] = size(imgQ); 

% Get the number of gray levels 
maxGV = max(img(:)); 


% Create GLCM initial Matrix 
C = zeros(maxGV, maxGV); 


% Positions 
delta_x = ceil(delta*cos(theta)); 
delta_y = ceil(delta*sin(theta)); 

%% Find Occurences 
for i = delta_x+1:m-delta_x 
    for j = delta_y+1:n-delta_y 
    if(imgQ(i, j) == imgQ(i+delta_x, j+delta_y)) 

     C(,) = C(,) + 1; 
    end 

    end 
    end 



end 
+0

你说什么“指数”问题? – rayryeng

+0

它已经解决了,我更新了代码 – Xeno1987

+0

然后请创建一个答案。人们会感到困惑,因为除非他们进入你的编辑历史,他们不会知道你已经解决了你的问题。要么,要么删除你的问题,如果你没有发现它有用。 – rayryeng

回答

0

答案可以通过确保内部嵌套双循环for有正确的索引来访问图像中找到。他们使用最外部的for循环作为索引而不是内部循环。 OP已经评论说,这与MATLAB给出的计算GLCM的方法略有不同,但它足以让OP忽略:

for o = 1:maxGV 
    for p = 1:maxGV 
     if(imgQ(i, j) == o & imgQ(i+delta_x, j+delta_y) == p) 
      C(o, p) = C(o, p) + 1; 
     end 
    end 
end