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

[FEA] Expose typestr to CuImage object for converting data type of the image to numpy.dtype #243

Closed
gigony opened this issue Mar 24, 2022 · 0 comments · Fixed by #246
Closed
Assignees
Labels
feature request New feature or request

Comments

@gigony
Copy link
Contributor

gigony commented Mar 24, 2022

Is your feature request related to a problem? Please describe.
It would be better if there is an easier way for converting the data type of the image to NumPy's datatype.

currently, a workaround is np.dtype(img.array_interface["typestr"]).

Describe the solution you'd like

Will expose typestr property to the image object so np.dtype(img.typestr) is possible.

Additional context
This feature is necessary for interoperability with other libraries/frameworks.

@gigony gigony added the feature request New feature or request label Mar 24, 2022
@gigony gigony self-assigned this Mar 24, 2022
@gigony gigony changed the title [FEA] Expose typestr to CuImage object for converting data type of the image to numpy.dtype. [FEA] Expose typestr to CuImage object for converting data type of the image to numpy.dtype Mar 24, 2022
@rapids-bot rapids-bot bot closed this as completed in #246 Mar 31, 2022
rapids-bot bot pushed a commit that referenced this issue Mar 31, 2022
)

- Expose typestr property on CuImage object
- Expose DLDataType and DLDataTypeCode under cucim.clara

Without this patch,
DLDataType and DLDataTypecode can be accessible with the below workaround.

```python
>>> from cucim import CuImage
>>> a = CuImage("notebooks/input/image.tif")
>>> b = a.read_region((0,0), (10,10))
>>> import numpy as np
>>> np.dtype(b.__array_interface__["typestr"]) # b would expose `__cuda_array_interface__` if memory is in GPU.
dtype('uint8')
```

With this patch, we can convert data type to NumPy's dtype easily, and also can access cuCIM's DLDataType.

```python
>>> from cucim import CuImage
>>> a = CuImage("notebooks/input/image.tif")
>>> b = a.read_region((0,0), (10,10))
>>> import numpy as np
>>> b.typestr
'|u1'
>>> np.dtype(b.typestr) == np.uint8
True
>>> from cucim.clara import DLDataType, DLDataTypeCode
>>> b.dtype == DLDataType(DLDataTypeCode.DLUInt, 8, 1)
True
```

Fixes #243

Authors:
  - Gigon Bae (https://github.com/gigony)

Approvers:
  - https://github.com/jakirkham

URL: #246
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant