DIPlib / diplib

Quantitative Image Analysis in C++, MATLAB and Python
https://diplib.org
Apache License 2.0
227 stars 49 forks source link

GetImageChainCodes: TypeError when uint32 is passed in #61

Closed acycliq closed 4 years ago

acycliq commented 4 years ago

Component PyDIP: 3.0b6

Describe the bug Am I doing something wrong here please. I have installed diplib only with the pip command pip install diplib and I am getting this error when I run the code below To Reproduce

import numpy as np
import diplib as dip

img = np.identity(3, dtype=np.uint32)
cc = dip.GetImageChainCodes(img)
print('Found %d objects' % len(cc) )
print('img is %s' % img.dtype)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-3951e39274b8> in <module>
      2 import diplib as dip
      3 img = np.identity(3, dtype=np.uint32)
----> 4 cc = dip.GetImageChainCodes(img)
      5 print('Found %d objects' % len(cc) )
      6 print('img is %s' % img.dtype)

TypeError: GetImageChainCodes(): incompatible function arguments. The following argument types are supported:
    1. (labels: diplib.PyDIP_bin.Image, objectIDs: List[int] = [], connectivity: int = 2) -> List[diplib.PyDIP_bin.ChainCode]

Invoked with: array([[1, 0, 0],
       [0, 1, 0],
       [0, 0, 1]], dtype=uint32)

It looks to work fine with uint8, uint16, uint64

img = np.identity(3, dtype=np.uint8)
cc = dip.GetImageChainCodes(img)
print('Found %d objects' % len(cc) )
print('img is %s' % img.dtype)

>> Found 1 objects
>> img is uint8

System information: I am on Windows 10, Python 3.7, numpy 1.18.5 I do not know if it is relevant but when I am importing diplipI am getting the message: PyDIPjavaio unavailable: DLL load failed: The specified module could not be found. (libjvm not found)

crisluengo commented 4 years ago

This is interesting! On macOS and Linux, the 32-bit integers worked fine, but it was the 64-bit ones that don't work. Turns out that Python uses the "long" C type when it has a chance, on Windows "long" is a 32-bit integer, on macOS and Linux it's a 64-bit integer. So now I've added support to receive "long" integer matrices from Python. I'm watching the tests run on Travis, if they succeed I'll build a new release.

crisluengo commented 4 years ago

@acycliq ~Travis is building a new release. You can check progress here: https://travis-ci.org/github/DIPlib/diplib/builds/736767681~ The Windows binaries are released to PyPI.

When it's complete, you should be able to upgrade your DIPlib installation with

pip install diplib --upgrade
acycliq commented 4 years ago

Thanks so much Cris, it works fine!