# Newbie question on using filters and access imagedata

**URL:** <https://discourse.slicer.org/t/newbie-question-on-using-filters-and-access-imagedata/3978>\
**Category:** Development\
**Tags:** extensions-manager\
**Created:** [September 3, 2018, 7:49pm UTC](https://discourse.slicer.org/t/newbie-question-on-using-filters-and-access-imagedata/3978 "2018-09-03T19:49:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niels](https://avatars.discourse-cdn.com/v4/letter/n/ebca7d/32.png) [@Niels](https://discourse.slicer.org/u/Niels)\
**Post date:** [September 3, 2018, 7:49pm UTC](https://discourse.slicer.org/t/newbie-question-on-using-filters-and-access-imagedata/3978/1 "2018-09-03T19:49:59Z")

</div>

Hi all,

I am working on a module for exporting image data from slicer to a format for our medical simulation systems. I have started with a simple python module for thresholding, scaling and normalizing the data (0 – 1) and writing them to a file format our simulation system can read. Getting the image data and writing them to file seems straight forward.

But for me it is not clear how to change the actual image data and get the values for writing them to an output file. I see people using vtk filters to change the displayed views, but they do not change the actual image data.

My code looks somewhat like this:

```
# getimage dimentions and spacing
imageData = inVolumeData.GetImageData()
imageDimention = imageData.GetDimensions()
scalarRange = imageData.GetScalarRange();
imageSpaceing = inVolumeData.GetSpacing()

# filter, let use existing filters and not make my own
shiftScale = vtk.vtkImageShiftScale()
shiftScale.SetInputData( imageData )
shiftScale.SetShift(3000)
shiftScale.SetScale(0.07)
shiftScale.SetOutputScalarTypeToUnsignedChar()
### how to get the raw data values for output the file?
### and update the slicer views?
```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 3, 2018, 8:18pm UTC](https://discourse.slicer.org/t/newbie-question-on-using-filters-and-access-imagedata/3978/2 "2018-09-03T20:18:02Z")

</div>

You can do it quite easily using numpy: [https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Modify\_voxels\_in\_a\_volume](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Modify_voxels_in_a_volume)

However, I would strongly suggest _not_ to rescale actual voxel values only for display: voxel values may have physical meaning (Hounsfield unit, etc) that you would lose by “normalizing” them; it may also increase storage requirements by a factor of 4-8x if you rescale to 0-1 range, because you need to use float or double data type; you may need to implement rescaling in the end-user software anyway, as window/level often need to be adjusted depending on the specific task and user preference. There are several more reasons.

---

<div class="post-metadata">

**Author:** ![Niels](https://avatars.discourse-cdn.com/v4/letter/n/ebca7d/32.png) [@Niels](https://discourse.slicer.org/u/Niels)\
**Post date:** [September 25, 2018, 1:41pm UTC](https://discourse.slicer.org/t/newbie-question-on-using-filters-and-access-imagedata/3978/3 "2018-09-25T13:41:13Z")

</div>

Hi lassoan,

Thanks for your answer, I got it to work!
