InsightSoftwareConsortium / InsightSoftwareConsortium/ITK

BUG: RGBUC2 not recognized with slice of numpy array

Open
#3,429 0 comments 0 reactions 0 assignees View on GitHub
type:Bug
Dominant language
C++
Stars
1.7k
Forks
748
Avg merge
1d 1h
Merged PRs (30d)
64

Description

### Description
`GetImageFromArray` works from an ordinary numpy array that has 3 colors as its last dimension to produce an ITK image of type `itkImageRGBUC2`. However, if a slice of the array is used, the fact that there are 3 colors is not recognized at the appropriate time, so the choice of `itkImageRGBUC2` is not taken. The image produced is instead of type `itkVectorImageUC2`

### Steps to Reproduce
```Python
import numpy as np
import itk
array = np.zeros((40, 50, 3), np.uint8)
patch = array[10:20, 10:20, :]
print(f"type(itk.GetImageFromArray(array, is_vector=True)) = {type(itk.GetImageFromArray(array, is_vector=True))}")
print(f"type(itk.GetImageFromArray(patch, is_vector=True)) = {type(itk.GetImageFromArray(patch, is_vector=True))}")
```

### Expected behavior
```Python
type(itk.GetImageFromArray(array, is_vector=True)) =
type(itk.GetImageFromArray(patch, is_vector=True)) =
```

### Actual behavior
```Python
type(itk.GetImageFromArray(array, is_vector=True)) =
type(itk.GetImageFromArray(patch, is_vector=True)) =
```

### Reproducibility
100%

### Versions
ITK 5.2.1

### Environment

Python 3.8.10 running on Ubuntu 20.04.

### Additional Information
```Python
print(f"array.flags = {array.flags}")
print(f"patch.flags = {patch.flags}")
```
shows that `array.flags['C_CONTIGUOUS'] == True` but `patch.flags['C_CONTIGUOUS'] == False`, which may be the problem.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.