Skip to content

Instantly share code, notes, and snippets.

@vtta
Created April 14, 2019 10:14
Show Gist options
  • Save vtta/a8be109a862f5bab8856a283b24b0ca5 to your computer and use it in GitHub Desktop.
Save vtta/a8be109a862f5bab8856a283b24b0ca5 to your computer and use it in GitHub Desktop.
Gray Level Co-occurrence Matrix in Octave
function Y=glcm(X, dx, dy, grayScale)
% (dx, dy):
% ( 1, 0) 0°
% ( 0, 1) 45°
% ( 1, 1) 90°
% (-1, 1) 135°
[m, n] = size(X);
maxGrayScale = max(X) + 1;
X = floor(X.*grayScale./maxGrayScale);
Y = zeros(grayScale,grayScale);
for i = 1:m-dy
for j = 1:n-dx;
r = X(i,j)+1;
c = X(i+dy, j+dx)+1;
Y(r,c) = Y(r,c)+1;
end
end
Y = Y./(m*n);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment