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

**URL:** https://discourse.itk.org/t/viewer-show-3d-numpy-array-with-colours-specified-by-array/5439
**Category:** Beginner Questions
**Tags:** python
**Created:** [October 24, 2022, 9:29am UTC](https://discourse.itk.org/t/viewer-show-3d-numpy-array-with-colours-specified-by-array/5439 "2022-10-24T09:29:59Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Kevin\_Sweeney](https://discourse.itk.org/user_avatar/discourse.itk.org/kevin_sweeney/32/2947_2.png) [@Kevin\_Sweeney](https://discourse.itk.org/u/Kevin_Sweeney)
#### Post date: [October 24, 2022, 9:29am UTC](https://discourse.itk.org/t/viewer-show-3d-numpy-array-with-colours-specified-by-array/5439/1 "2022-10-24T09:29:59Z")

</div>

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?

**Code:**  
`view(array, rotate=False, axes=False, view_mode='XPlane')`

**Desired:**

 ![Screenshot 2022-10-24 at 10.21.15](https://discourse.itk.org/uploads/default/original/2X/5/50cfbf9da9f05d1bcaa9d82128ee00442c550cab.png)

**Actual:**  
 ![Screenshot 2022-10-24 at 10.21.53](https://discourse.itk.org/uploads/default/original/2X/7/755c16d17d8c78f1be3249cae64caf38034443cd.png)

**Aside**  
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`)

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [October 24, 2022, 1:33pm UTC](https://discourse.itk.org/t/viewer-show-3d-numpy-array-with-colours-specified-by-array/5439/2 "2022-10-24T13:33:12Z")

</div>

@matt.mccormick or @PaulHax might answer this.

---

<div class="post-metadata">

### Author: ![PaulHax](https://discourse.itk.org/user_avatar/discourse.itk.org/paulhax/32/2949_2.png) [@PaulHax](https://discourse.itk.org/u/PaulHax)
#### Post date: [October 24, 2022, 1:59pm UTC](https://discourse.itk.org/t/viewer-show-3d-numpy-array-with-colours-specified-by-array/5439/3 "2022-10-24T13:59:04Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Kevin\_Sweeney](https://discourse.itk.org/user_avatar/discourse.itk.org/kevin_sweeney/32/2947_2.png) [@Kevin\_Sweeney](https://discourse.itk.org/u/Kevin_Sweeney)
#### Post date: [October 24, 2022, 2:51pm UTC](https://discourse.itk.org/t/viewer-show-3d-numpy-array-with-colours-specified-by-array/5439/4 "2022-10-24T14:51:59Z")

</div>

@PaulHax

Thanks for your reply. Please see below.

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

```

 ![Screenshot 2022-10-24 at 15.45.36](https://discourse.itk.org/uploads/default/original/2X/9/963d4c6e209663cee1385528b17f565a35ddeb7f.jpeg)

Name: itkwidgets  
Version: 0.32.0

---

<div class="post-metadata">

### Author: ![PaulHax](https://discourse.itk.org/user_avatar/discourse.itk.org/paulhax/32/2949_2.png) [@PaulHax](https://discourse.itk.org/u/PaulHax)
#### Post date: [October 25, 2022, 12:41pm UTC](https://discourse.itk.org/t/viewer-show-3d-numpy-array-with-colours-specified-by-array/5439/5 "2022-10-25T12:41:41Z")

</div>

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](https://discourse.itk.org/t/image-type-for-an-itk-image-from-numpy-array/2348)

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [November 24, 2022, 2:52am UTC](https://discourse.itk.org/t/viewer-show-3d-numpy-array-with-colours-specified-by-array/5439/6 "2022-11-24T02:52:07Z")

</div>

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

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

```

[Here is a full example](https://github.com/InsightSoftwareConsortium/itkwidgets/blob/main/examples/integrations/itk/MulticomponentNumPy.ipynb).

 ![image](https://discourse.itk.org/uploads/default/original/2X/f/f46a87048e8eff7db9f7d968b51fc801ed452bb6.png)
