Harralick feature extraction - correlation range problem

Hello, I am student and I am trying to learn some methods to texture discrimination. I am working on free UIUC texture database. In my program I am using this function to extract Harakick Features:
It seems to work nice, but correlation output of my pictures isn't between 0-1 range as it should be. Sometimes it's like ~700-1400. There is a sample of my code:
DatabaseSize=330; % 330 pictures
S=1;
N=11;
DB=cell(1,DatabaseSize);
PIC = 'S100%dL%d.jpg';
%I place all pictures to the table in form of 256x256 matrices, greyscale (0-255)
for i=1:DatabaseSize
DB{i}=imread(sprintf(PIC,S,N));
N=N+1;
if (N==41)
S=S+1;
N=11;
end
end
%creating glcm from jpg, grayscale picture of texture
for k=1:DatabaseSize
glcm0 = graycomatrix(DB{k}, 'offset', [0 1])
H0=haralick(glcm0);
end
Example of output:
0,0878234361108107
1,16456801470588
768,053407060767
12,6160448261336
0,645518095388608
6,63258272058824
25,9959507137929
2,12700480838163
2,83962634798163
0,0366762522066118
1,06815713592175
-0,189004327906360
0,668748281120083
Well 768 isn't for sure in range 0-1. I don't know where is the problem, because when I check the implementation of Haralicks equation or try other equations for calculating correlations I always get similar range ~1000 not 0-1. Do you know where might be the problem?

Answers (3)

Okay I investigated it myself. I tried to implement equation of Correlation showed by prof. Hall-Beyer (<http://www.fp.ucalgary.ca/mhallbey/)>. It worked. Then I've comparised the codes of Stephan Winzec and mine based of Hall-Beyers. I noticed, Stephan Winzec is using matlab fuctions such as mean() and std() to calculate mean and standard deviation from sums of rows/columns while prof. Hall-Beyer gives special equations for those valuse. When I've implemented those values to Stephan Winzec code it worked and gave the same value as code based on Hall-Beyers.
It's working then, I've fixed it myself.
Thanks
The first experiment I would do would be to im2double() the image before doing any further processing on it.

1 Comment

And after that, try to contact the author. None of us here know all the internal details of that File Exchange submission, nor do we have the time to dive into it, understand it, find the error (if there is one), and explain it.

Sign in to comment.

I've tried using im2double() command. There is experiment code I've created:
%haralick test
clear all;
A=imread('S1001L11.jpg');
A1=im2double(A);
TESTglcm = graycomatrix(A, 'offset', [0 1]);
F=haralick(TESTglcm);
TESTglcm1 = graycomatrix(A1, 'offset', [0 1]);
F1=haralick(TESTglcm);
Output:
0,0774961215337851 %Energy
0,578523284313726 % Contrast
2491,43280449342 % Correlation still not between 0-1
20,7553844975490 % Sum of Variances
0,777863640648568 % Inverse Difference Moment
8,65049019607843 % Sum Average
47,7940428015697 % Sum Variance
2,35341803540218 % Sum Entropy
2,80570105054169 % Entropy
0,0506959502934139 % Difference Variance
0,839289179310450 % Difference Entropy
-0,397708963316390 % Information Measures of Correlation 1&2
0,866994276250196
A (uint8), and A1(double) are of course different, while GLCM's created from them and Haralick features are the same.
I've already tried to contact autor (at mathworks.com and directly to his e-mail) before I decided to ask for your help, I am still waiting for his answer. So if you dont have time to dive into details of that File of Exchange I will show it here:
If correlation isn't giving the satisfying result (not in 0-1 range), then maybe something is wrong with the implementation of equation:
glcm is input to function:
S=size(glcm,1);
%normalization:
M = glcm/sum(glcm(:));
%sum of columns - tested, output is row vector
py = sum(M,1);
%sum of rows - tested, output is column vector
px = sum(M,2);
f_3=zeros(S);
for i=1:S
for j=1:S
f_3(i,j) = i*j*M(i,j);
end
end
% Correlation
ux = mean(px); sx=std(px);
uy = mean(py); sy=std(py);
f3 =(sum(f_3(:))-(ux*uy))/(sx*sy);
So thats mainly the code calculating the correlation. I post original equations for Haralick correlation (from year 1973) feature here, in case you don't have time to dig into it:
Please help me to find why it's calculating it wrong.

1 Comment

TESTglcm1 = graycomatrix(A1, 'offset', [0 1]);
F1=haralick(TESTglcm);
There is TESTglcm1 not TESTglcm. But it doesnt change a thing as the matrixes are the same.

Sign in to comment.

Tags

Asked:

on 22 Dec 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!