Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Fix greycoprops correlation always returning 1 #2532

Merged
merged 1 commit into from
Sep 24, 2018

Conversation

evanlimanto
Copy link
Contributor

Fixes issue #2012 by always normalizing the Gray-level Co-occurrence Matrices to a sum of 1.

@codecov-io
Copy link

codecov-io commented Feb 21, 2017

Codecov Report

Merging #2532 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #2532      +/-   ##
==========================================
+ Coverage   90.53%   90.54%   +<.01%     
==========================================
  Files         304      304              
  Lines       21706    21715       +9     
  Branches     1872     1872              
==========================================
+ Hits        19652    19661       +9     
  Misses       1714     1714              
  Partials      340      340
Impacted Files Coverage Δ
skimage/feature/tests/test_texture.py 100% <100%> (ø)
skimage/feature/texture.py 76.78% <100%> (+1.08%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 795e07f...daa831a. Read the comment docs.

@@ -138,21 +138,21 @@ def test_contrast(self):
normed=True, symmetric=True)
result = np.round(result, 3)
contrast = greycoprops(result, 'contrast')
np.testing.assert_almost_equal(contrast[0, 0], 0.586)
np.testing.assert_almost_equal(round(contrast[0, 0], 3), 0.585)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert_almost_equal should have a digits keyword, so that you don't have to use round

@@ -214,6 +214,12 @@ def greycoprops(P, prop='contrast'):
assert num_dist > 0
assert num_angle > 0

# normalize each GLMC
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add a catch for normed=False, that mentions that it now always happens?

Also, add a test that would catch a previously failing case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By catch do you mean a warning?

@evanlimanto evanlimanto force-pushed the greycoprops-normalize branch 3 times, most recently from acb995e to be3e56b Compare February 26, 2017 06:59
@evanlimanto
Copy link
Contributor Author

@stefanv I've updated the docstring in skimage/feature/texture.py

@sciunto sciunto added the bug label Feb 26, 2017
def test_non_normalized_glcm(self):
img = (np.random.random((100, 100)) * 8).astype(np.uint8)
p = greycomatrix(img, [1, 2, 4, 5], [0, 0.25, 1, 1.5], levels=8)
np.testing.assert_(np.min(greycoprops(p, 'correlation')) < 1.0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be np.max?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@@ -166,6 +167,7 @@ def greycoprops(P, prop='contrast'):
.. math:: \\sum_{i,j=0}^{levels-1} P_{i,j}\\left[\\frac{(i-\\mu_i) \\
(j-\\mu_j)}{\\sqrt{(\\sigma_i^2)(\\sigma_j^2)}}\\right]

Each GLCM is normalized to have a sum of 1 before calculation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "before calculation" mean here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated comment to "before computation of texture properties".

@sciunto
Copy link
Member

sciunto commented Apr 15, 2017

@stefanv Wouldn't it deserve a special note for the next release? Also, greycoprops and greycomatrix now have different default behviors. One is not normalized by default and the second is always normalized.

@sciunto sciunto added this to the 0.14.2 milestone Sep 19, 2018
@sciunto
Copy link
Member

sciunto commented Sep 19, 2018

This bugfix is pending for a while. Anyone to review @scikit-image/core

@jni jni merged commit da11c23 into scikit-image:master Sep 24, 2018
@jni
Copy link
Member

jni commented Sep 24, 2018

@sciunto You are absolutely right! Thanks for the ping, thanks @evanlimanto for the fix, and thanks everyone else who contributed to the discussion in #2012!

@MattWenham
Copy link

I'm currently working on some speedups for greycomatrix and greycoprops, which this merge somewhat negates. In particular, greycoprops now always normalises the input array, even if greycomatrix has already normalised it. I have moved the normalisation in greycomatrix into Cython and it is now considerably faster. I could do the same for the normalisation in greycoprops, but ideally, if the input is already normalised, it should not be normalised a second time.

One possible solution would be to have an (optional) normed flag on the input to greycoprops to indicate if the input array has already been normalised. This may be somewhat dangerous, as checking for a normalised input array would be almost as slow as actually normalising it, so greycoprops would be taking it on faith that the normalisation had actually taken place. Thoughts?

If this is not the appropriate place for this discussion, please let me know where I should take it.

@sciunto
Copy link
Member

sciunto commented Sep 26, 2018

@MattWenham Thanks for keeping this up. Github is the right place. I would suggest to continue the discussion in #3413 for more visibility (even copy paste adapt your comment to #3413).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants