luispedro / mahotas

Computer Vision in Python
https://mahotas.rtfd.io
Other
844 stars 148 forks source link

Haralick feature is incorrect #36

Closed manuels closed 9 years ago

manuels commented 10 years ago

The Haralick features with indices 6 and 9 (code here and here) are calculated incorrectly. Index 9 should be the variance of the pixel value differences and not the variance of the probabilities of the pixel values (compare Wikipedia article, 2nd versus 3rd equation).

And index 6 should be np.dot((tk-feats[5])**2, px_plus_y) (compare http://www.iaeng.org/IJCS/issues_v36/issue_1/IJCS_36_1_09.pdf)

luispedro commented 10 years ago

On 01/28/2014 10:29 AM, manuels wrote:

Index 9 should be the variance of the pixel value differences and not the variance of the probabilities of the pixel values

Haralick 1973 has f{10} = variance of p{x-y} and p_{x-y} is the normalized array. Normalized means probabilities. The code against which I benchmarked mahotas also had this interpretation.

*

Your interpretation is that it's the variance of |x-y|. Not unreasonable, actually.

Changing interpretations now would break backwards compatibility, though. I'll think about it.

And index 6 should be np.dot((tk-feats[5])**2, px_plus_y) (compare http://www.iaeng.org/IJCS/issues_v36/issue_1/IJCS_36_1_09.pdf)

That's the same result. Just that you have more temporary variables that way.

Tx Luis

manuels commented 10 years ago

And index 6 should be np.dot((tk-feats[5])**2, px_plus_y) (compare http://www.iaeng.org/IJCS/issues_v36/issue_1/IJCS_36_1_09.pdf)

That's the same result. Just that you have more temporary variables that way.

Not really, is it?

  sum((k-f)^2*P(k))
= sum((k^2 - 2kf + f^2)*P(k))
= sum(k^2*P(k)) - 2*f*sum(k*P(k)) + f^2
manuels commented 10 years ago
= sum(k^2*P(k)) - 2*f^2 + f^2
= sum(k^2*P(k)) - f^2

sorry, you are right about this one ;)