Viewer: Show 3D numpy array with colours specified by array

I have a 3D numpy array (shape = (224, 224, 3)) which defines the RGB values at each pixel (uint8).

How can I use ikwidgets.view() method to show this array using the RBG colours instead of a colourmap?

view(array, rotate=False, axes=False, view_mode='XPlane')


Screenshot 2022-10-24 at 10.21.53

The view_mode='XPlane' is not setting the view mode as expected. The view is still in volume mode and i need to click on the icon to change to X Plane. I have tried (XPlane, x, 1)

@matt.mccormick or @PaulHax might answer this.

Hi Kevin,

Thanks for the 2 issues reported here. Can you post a couple lines of python that generate the numpy array. My guess is that the image is interpreted as a “volume” 3 voxels deep, rather than a 2D image with 3 components. Maybe we can convert to a image format where we can specify that. If the viewer recognizes 3 components it will default to red/green/blue. Can see the number of components as tabs with checkboxes in the middle of the UI.


Thanks for your reply. Please see below.

array = np.random.randint(0, 255, size=(224, 224, 3))
array.shape # (224, 224, 3)

Name: itkwidgets
Version: 0.32.0

I actually don’t know how to convert an numpy to a itk or vtk image with 3 components. This looks promising: Image type for an ITK image from numpy array

1 Like

We can clarify that the array should be interpreted as a multicomponent 2D image versus a 3D image with is_vector=True:

image = itk.image_from_array(array, is_vector=True)

Here is a full example.