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

Warning in local binary pattern if image dtype is not integer #2563

Closed
wants to merge 3 commits into from

Conversation

anshitag
Copy link
Contributor

@anshitag anshitag commented Mar 13, 2017

Description

Added warning to the user if they do not use integer type image with Local Binary Pattern function.
Changes made to function local_binary_pattern in scikit-image/skimage/feature/texture.py

File code checked with flake8, follows PEP08.

References

Closes #2522

@codecov-io
Copy link

codecov-io commented Mar 14, 2017

Codecov Report

Merging #2563 into master will decrease coverage by <.01%.
The diff coverage is 66.66%.

@@            Coverage Diff             @@
##           master    #2563      +/-   ##
==========================================
- Coverage   90.53%   90.53%   -0.01%     
==========================================
  Files         304      304              
  Lines       21706    21709       +3     
  Branches     1872     1873       +1     
==========================================
+ Hits        19652    19654       +2     
  Misses       1714     1714              
- Partials      340      341       +1
Impacted Files Coverage Δ
skimage/feature/texture.py 75.45% <66.66%> (-0.25%) ⬇️
skimage/morphology/watershed.py 78% <0%> (ø) ⬆️
skimage/filters/thresholding.py 95.21% <0%> (ø) ⬆️

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 520e752...5d1f270. Read the comment docs.

@@ -307,6 +309,12 @@ def local_binary_pattern(image, P, R, method='default'):
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.214.6851,
2004.
"""
match_datatype = re.search('int', str(image.dtype))
Copy link
Member

Choose a reason for hiding this comment

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

@anshitag take a look at this awesome feature of numpy:

In [3]: z = np.array([3])

In [4]: z.dtype
Out[4]: dtype('int64')

In [5]: z.dtype.kind
Out[5]: 'i'

In [6]: z = np.array([3.1])

In [7]: z.dtype.kind
Out[7]: 'f'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@soupault thanks for the input! I just have some doubts regarding the change.

I tried running this code for an image from skimage data of dtype uint8, and got the following result:

In [30]: from skimage import data
         image = data.load('brick.png')

In [31]: image.dtype
Out[31]: dtype('uint8')

In [32]: image.dtype.kind
Out[32]: 'u'

This image has been used in the example for LBP here.
Since there are only two outcomes for image.dtype.kind for integer numpy arrays i.e. i if signed integer and u if unsigned integer, should I directly check these characters (not use re)?


if image.dtype.kind not in ('i', 'u'):
warn('Image data type incorrect. Convert the image to integer type for'
' local_binary_pattern')
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
' local_binary_pattern')
' local_binary_pattern', stacklevel=2)

@@ -307,6 +308,11 @@ def local_binary_pattern(image, P, R, method='default'):
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.214.6851,
2004.
"""

if image.dtype.kind not in ('i', 'u'):
Copy link
Member

Choose a reason for hiding this comment

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

I think it's only 'u' since positive integers are required.

@emmanuelle
Copy link
Member

I was browsing through old PRs, this one seems easy enough to merge soon.

@alexdesiqueira
Copy link
Member

Hey everyone,
I'm closing this since it was superseded by #6272 (merged). Thank you for your work @anshitag @emmanuelle!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Local Binary Pattern
  
In progress
Development

Successfully merging this pull request may close these issues.

Unexpected behavior of skimage.feature.local_binary_pattern
5 participants