# Correct Application of a Smoothing filter on an IsoSurface

**URL:** https://discourse.vtk.org/t/correct-application-of-a-smoothing-filter-on-an-isosurface/6147
**Category:** Support
**Created:** [July 7, 2021, 2:27pm UTC](https://discourse.vtk.org/t/correct-application-of-a-smoothing-filter-on-an-isosurface/6147 "2021-07-07T14:27:53Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![vsrivastava](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/v/90db22/32.png) [@vsrivastava](https://discourse.vtk.org/u/vsrivastava)
#### Post date: [July 7, 2021, 2:27pm UTC](https://discourse.vtk.org/t/correct-application-of-a-smoothing-filter-on-an-isosurface/6147/1 "2021-07-07T14:27:53Z")

</div>

```auto
vtkSmartPointer<vtkMarchingCubes> iso = vtkSmartPointer<vtkMarchingCubes>::New();
iso->SetInputConnection(NrrdFileReader->GetOutputPort());
iso->ComputeGradientsOn();
iso->ComputeScalarsOff();
iso->SetValue(0, 1);
iso->Update();

vtkSmartPointer<vtkWindowedSincPolyDataFilter> smoother = vtkSmartPointer<vtkWindowedSincPolyDataFilter>::New();
smoother->SetInputData(iso->GetOutput());
smoother->SetNumberOfIterations(20);
double passband = 0.3;
smoother->SetPassBand(passband);
smoother->BoundarySmoothingOff();
smoother->FeatureEdgeSmoothingOn();
smoother->SetEdgeAngle(180);
smoother->NonManifoldSmoothingOff();
smoother->NormalizeCoordinatesOff();
smoother->Update(); 

vtkSmartPointer<vtkPolyDataMapper> isoMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
isoMapper->SetInputConnection(smoother->GetOutputPort());
isoMapper->ScalarVisibilityOff();

vtkSmartPointer<vtkActor> isoActor = vtkSmartPointer<vtkActor>::New();
isoActor->SetMapper(isoMapper);
isoActor->GetProperty()->SetColor(namecolors->GetColor3d("Ivory").GetData());

vtkSmartPointer<vtkOutlineFilter> outline = vtkSmartPointer<vtkOutlineFilter>::New();
outline->SetInputConnection(NrrdFileReader->GetOutputPort());

vtkSmartPointer<vtkPolyDataMapper> outlineMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
outlineMapper->SetInputConnection(outline->GetOutputPort());
	
vtkSmartPointer<vtkActor> outlineActor = vtkSmartPointer<vtkActor>::New();
outlineActor->SetMapper(outlineMapper);

ren1->AddActor(outlineActor);
ren1->AddActor(isoActor);
ren1->SetBackground(namecolors->GetColor3d("SlateGray").GetData());

```

 ![image](https://discourse.vtk.org/uploads/default/original/2X/e/e3accb1dcb07208547e46302eb2b90380b699a31.jpeg)

I had reconstructed a model from .nrrd file using the Marching cube algorithms.  
I was trying to apply smoothing to the model above, but it doesn’t seem to change. I wanted to confirm, if I had done it properly. Also, I am not sure if the outline filter needs to be changed in this case.

---

<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: [July 7, 2021, 3:15pm UTC](https://discourse.vtk.org/t/correct-application-of-a-smoothing-filter-on-an-isosurface/6147/2 "2021-07-07T15:15:23Z")

</div>

Try turning off feature edge smoothing (FeatureEdgeSmoothingOff()) and see what happens. The resolution of the volume / data is so low that the end effect is to create many sharp edges, which then become constraints to the smoothing process.

---

<div class="post-metadata">

### Author: ![vsrivastava](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/v/90db22/32.png) [@vsrivastava](https://discourse.vtk.org/u/vsrivastava)
#### Post date: [July 7, 2021, 5:15pm UTC](https://discourse.vtk.org/t/correct-application-of-a-smoothing-filter-on-an-isosurface/6147/3 "2021-07-07T17:15:12Z")

</div>

Thanks Will, but it still gives me the same result. I am not sure if I’ve correctly applied the filter.

---

<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: [July 7, 2021, 6:56pm UTC](https://discourse.vtk.org/t/correct-application-of-a-smoothing-filter-on-an-isosurface/6147/4 "2021-07-07T18:56:36Z")

</div>

Thanks for trying. Can you send the data?

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [July 7, 2021, 9:08pm UTC](https://discourse.vtk.org/t/correct-application-of-a-smoothing-filter-on-an-isosurface/6147/5 "2021-07-07T21:08:41Z")

</div>

See a correct usage of the filter for smoothing binary segmentations here:

> <https://github.com/Slicer/Slicer/blob/72d4a6e573b74cb519467a149181f221c8963823/Libs/vtkSegmentationCore/vtkBinaryLabelmapToClosedSurfaceConversionRule.cxx#L347-L362>

Note that if the input image was highly anisotropic then you cannot remove the staircase artifacts (without significant loss of relevant details) with surface smoothing at the end of your processing pipeline. Instead, to avoid these artifacts you can resample the input grayscale image to be approximately isotropic, and then apply contour filter and surface smoothing. See more detailed explanation and instructions in the [3D Slicer forum](https://discourse.slicer.org/t/staircase-aware-smoothing/5660) and [3D Slicer User Manual](https://slicer.readthedocs.io/en/latest/user_guide/modules/segmenteditor.html#generated-surface-contains-step-artifacts).

---

<div class="post-metadata">

### Author: ![vsrivastava](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/v/90db22/32.png) [@vsrivastava](https://discourse.vtk.org/u/vsrivastava)
#### Post date: [July 8, 2021, 1:07pm UTC](https://discourse.vtk.org/t/correct-application-of-a-smoothing-filter-on-an-isosurface/6147/6 "2021-07-08T13:07:02Z")

</div>

Uploading: output\_00126702-1-label.nrrd…

Will, PFA the file for the segmentation. Regards.

---

<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: [July 9, 2021, 2:37pm UTC](https://discourse.vtk.org/t/correct-application-of-a-smoothing-filter-on-an-isosurface/6147/7 "2021-07-09T14:37:21Z")

</div>

Thanks, I’ll take a look. Note that Andras works with this type of data much more than I do, so I would pay careful attention to what he wrote - I’m pretty sure he’s offering good advice.

---

<div class="post-metadata">

### Author: ![vsrivastava](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/v/90db22/32.png) [@vsrivastava](https://discourse.vtk.org/u/vsrivastava)
#### Post date: [July 9, 2021, 3:30pm UTC](https://discourse.vtk.org/t/correct-application-of-a-smoothing-filter-on-an-isosurface/6147/8 "2021-07-09T15:30:24Z")

</div>

Thank you Will and Andras, yes I 'm working on writing code for what Andras has shared as well. Will keep you guys posted as I am able to get the results from his method. Thanks again.
