# Downsampling 3D image data in VTK without aliasing?

**URL:** https://discourse.vtk.org/t/downsampling-3d-image-data-in-vtk-without-aliasing/3329
**Category:** Support
**Created:** [May 19, 2020, 1:54am UTC](https://discourse.vtk.org/t/downsampling-3d-image-data-in-vtk-without-aliasing/3329 "2020-05-19T01:54:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![msmerps](https://discourse.vtk.org/user_avatar/discourse.vtk.org/msmerps/32/1559_2.png) [@msmerps](https://discourse.vtk.org/u/msmerps)
#### Post date: [May 19, 2020, 1:54am UTC](https://discourse.vtk.org/t/downsampling-3d-image-data-in-vtk-without-aliasing/3329/1 "2020-05-19T01:54:42Z")

</div>

Hi, I would like downsample some 3D image data by a factor of 2 without introducing aliasing artifact as described here:

> **[Aliasing and image resizing – part 3](https://blogs.mathworks.com/steve/2017/01/16/aliasing-and-image-resizing-part-3/)**
>
> Today I'll try to wrap up my discussion about how aliasing affects image resizing and about how the imresize function tries to prevent it. (This is called antialiasing.) Let me show you where we are going. Here is the zone plate image I showed last...

I am able to do the downsampling with vtkImageReslice.SetOutputSpacing. However, it doesn’t appear to apply an anti-aliasing filter before the downsampling. Is that correct? If so, is there an alternative method I can use that does apply an anti-aliasing filter?  
thank you in advance,  
-M

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [May 19, 2020, 1:40pm UTC](https://discourse.vtk.org/t/downsampling-3d-image-data-in-vtk-without-aliasing/3329/2 "2020-05-19T13:40:48Z")

</div>

The easiest way to do antialiased resizing is with [vtkImageResize](https://vtk.org/doc/nightly/html/classvtkImageResize.html). This filter will perform band-limited sinc interpolation. You can use it to adjust the spacing as follows (using Python as an example):

```python
resize = vtkImageResize()
resize.SetResizeMethodToOutputSpacing()
resize.SetOutputSpacing(sx, sy, sz)

```

Alternatively, you can use an antialiased interpolator with vtkImageReslice, though this isn’t quite as efficient:

```python
interpolator = vtkImageSincInterpolator()
interpolator.AntialiasingOn()

reslice = vtkImageReslice()
reslice.SetInterpolator(interpolator)
reslice.SetOutputSpacing(sx, sy, sz)

```

The idea here is that a windowed and stretched sinc kernel is used to perform the resizing with antialiasing.

---

<div class="post-metadata">

### Author: ![msmerps](https://discourse.vtk.org/user_avatar/discourse.vtk.org/msmerps/32/1559_2.png) [@msmerps](https://discourse.vtk.org/u/msmerps)
#### Post date: [May 20, 2020, 8:41pm UTC](https://discourse.vtk.org/t/downsampling-3d-image-data-in-vtk-without-aliasing/3329/3 "2020-05-20T20:41:47Z")

</div>

Thanks, yet again @dgobbi! I will try using vtkImageResize and will let you know how it goes. 🙂

---

<div class="post-metadata">

### Author: ![msmerps](https://discourse.vtk.org/user_avatar/discourse.vtk.org/msmerps/32/1559_2.png) [@msmerps](https://discourse.vtk.org/u/msmerps)
#### Post date: [May 21, 2020, 9:14pm UTC](https://discourse.vtk.org/t/downsampling-3d-image-data-in-vtk-without-aliasing/3329/4 "2020-05-21T21:14:44Z")

</div>

vtkImageResize worked great! Chalk up another win for @dgobbi.
