# How to avoid the sawtooth from vtkImageReslice?

**URL:** https://discourse.vtk.org/t/how-to-avoid-the-sawtooth-from-vtkimagereslice/5023
**Category:** Support
**Created:** [January 17, 2021, 3:34am UTC](https://discourse.vtk.org/t/how-to-avoid-the-sawtooth-from-vtkimagereslice/5023 "2021-01-17T03:34:09Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhang-qiang-github/32/2519_2.png) [@zhang-qiang-github](https://discourse.vtk.org/u/zhang-qiang-github)
#### Post date: [January 17, 2021, 3:34am UTC](https://discourse.vtk.org/t/how-to-avoid-the-sawtooth-from-vtkimagereslice/5023/1 "2021-01-17T03:34:09Z")

</div>

I find there is sawtooth for the output of `vtkImageReslice`, how can I avoid this sawtooth?

 ![image](https://discourse.vtk.org/uploads/default/original/2X/3/39aad969a40e1a7524ca6d54c4077ff95c34eb11.jpeg)

Any suggestion is appreciated!

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [January 18, 2021, 11:18am UTC](https://discourse.vtk.org/t/how-to-avoid-the-sawtooth-from-vtkimagereslice/5023/2 "2021-01-18T11:18:23Z")

</div>

Off the top of my head, have you tried vtkFlyingEdgesPlaneCutter ? It’s likely to be slower though… make sure you are building with threading enabled.

---

<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: [January 18, 2021, 3:44pm UTC](https://discourse.vtk.org/t/how-to-avoid-the-sawtooth-from-vtkimagereslice/5023/3 "2021-01-18T15:44:24Z")

</div>

The interpolation in vtkImageReslice only interpolates between voxels within the image, but it does not interpolate between the image and the background. Because of this, the boundary between the image and the background is not smoothed.

One solution is to pad the image before using vtkImageReslice. The vtkImageConstantPad filter can be used for this. For example, if your image is 256x256,

```auto
auto pad = vtkSmartPointer<vtkImageConstantPad>::New();
pad->SetInputData(...); // (or SetInputConnection)
pad->SetExtent(-1, 256, -1, 256, 0, 0);

```

This requires a negative value to pad at the start of the image. Also note that for a 3D image the “0, 0” should be replaced by the z extent.

Padding with 1 pixel is good for linear interpolation, but if you are using cubic interpolation then a pad of 2 pixels should be used.

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhang-qiang-github/32/2519_2.png) [@zhang-qiang-github](https://discourse.vtk.org/u/zhang-qiang-github)
#### Post date: [January 27, 2021, 2:54pm UTC](https://discourse.vtk.org/t/how-to-avoid-the-sawtooth-from-vtkimagereslice/5023/4 "2021-01-27T14:54:53Z")

</div>

Thank you for you kindly reply.
