Skip to content

ValueError in exposure.histogram #1228

@Dimchord

Description

@Dimchord

There is a bug in the way exposure.histogram handles integer arrays. The problem is that the values of the array are shifted because np.bincount can only handle non-negative values. There is however no protection from integer overflow, as in the following example:

>>> from skimage import exposure
>>> exposure.histogram(array([-1,127],dtype=int8))

Traceback (most recent call last):

  File "<ipython-input-93-11812a617109>", line 1, in <module>
    exposure.histogram(array([-1,127],dtype=int8))

  File "C:\Anaconda\lib\site-packages\skimage\exposure\exposure.py", line 60, in histogram
    hist = np.bincount(image.ravel() - offset)

ValueError: The first argument of bincount must be non-negative

My solution would be to view the array as the equivalent unsigned type in the call to bincount.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions