ITK
ITK copied to clipboard
BUG: RGBUC2 not recognized with slice of numpy array
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
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
type(itk.GetImageFromArray(array, is_vector=True)) = <class 'itk.itkImagePython.itkImageRGBUC2'>
type(itk.GetImageFromArray(patch, is_vector=True)) = <class 'itk.itkImagePython.itkImageRGBUC2'>
Actual behavior
type(itk.GetImageFromArray(array, is_vector=True)) = <class 'itk.itkImagePython.itkImageRGBUC2'>
type(itk.GetImageFromArray(patch, is_vector=True)) = <class 'itk.itkVectorImagePython.itkVectorImageUC2'>
Reproducibility
100%
Versions
ITK 5.2.1
Environment
Python 3.8.10 running on Ubuntu 20.04.
Additional Information
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.