# How to convert vtkData to RGB data?

**URL:** <https://discourse.slicer.org/t/how-to-convert-vtkdata-to-rgb-data/25650>\
**Category:** Support\
**Tags:** python\
**Created:** [October 12, 2022, 8:31am UTC](https://discourse.slicer.org/t/how-to-convert-vtkdata-to-rgb-data/25650 "2022-10-12T08:31:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![user4](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/user4/32/13172_2.png) [@user4](https://discourse.slicer.org/u/user4)\
**Post date:** [October 12, 2022, 8:31am UTC](https://discourse.slicer.org/t/how-to-convert-vtkdata-to-rgb-data/25650/1 "2022-10-12T08:31:31Z")

</div>

Hi,all.  
Here is one red slice of my image data(.vtk format)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/9/99ce1ffbad7de7a3bc42614a86473c0f17144d1a.jpeg)

I get this slice with the following code,

```auto
volume_node = slicer.util.getNode("vtkMRMLScalarVolumeNode1")
image = slicer.util.arrayFromVolume(volume_node)
red_slice = image[50,:,:]

```

However,its voxels are raw values which is not in [0,255] range.If I take a screenshot on this red slice and get a .png format picture,its pixels can convert into range [0,255].  
I want to know if there is a way to convert the slice with the raw data.  
This pseudocode is used to illustrate the idea.

```auto
red_slice = image[50,:,:] # image is raw data, voxels are not in [0,255]
gray_red_slice = convert_to_gray_image(image[50,:,:]) # some function/methods to convert the intensity values

```

Thanks in advance for your help and advice!

---

<div class="post-metadata">

**Author:** ![ebrahim](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ebrahim/32/13403_2.png) [@ebrahim](https://discourse.slicer.org/u/ebrahim)\
**Post date:** [October 12, 2022, 2:10pm UTC](https://discourse.slicer.org/t/how-to-convert-vtkdata-to-rgb-data/25650/2 "2022-10-12T14:10:32Z")

</div>

You could transform the values into the [0,255] range by shifting and scaling them:

```python
a = red_slice.min()
b = red_slice.max()
gray_red_slice = 255 * (red_slice-a) / (b-a)

```
