# Smoothing causes offset of portion of copied segment

**URL:** <https://discourse.slicer.org/t/smoothing-causes-offset-of-portion-of-copied-segment/21340>\
**Category:** Support\
**Created:** [January 5, 2022, 5:59pm UTC](https://discourse.slicer.org/t/smoothing-causes-offset-of-portion-of-copied-segment/21340 "2022-01-05T17:59:24Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [January 5, 2022, 5:59pm UTC](https://discourse.slicer.org/t/smoothing-causes-offset-of-portion-of-copied-segment/21340/1 "2022-01-05T17:59:24Z")

</div>

I have a large segment (whole body) and I want to make a copy of this and delete everything but the head. This all works fine, except when I view the head segment and the body segment in the 3D view with smoothing turned on, the head only segment is offset by a few pixels. This is only in the 3D view and only if smoothing is turned on.

Here is body (orange) and head (blue) together, with smoothing turned off. Blue is a direct copy of orange.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/0/40a781c76dc70c599c396cb255d4649b119f3aba.jpeg)

Now, head and body with smoothing on, set to 0.1:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/2/2206c538d3d994dbbe8411b0c5b53c7457160eb0.jpeg)

Note the shift to the right of the image of the blue segment when smoothing is turned on.

Any ideas? Thanks!

-Hollister

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [January 7, 2022, 10:48pm UTC](https://discourse.slicer.org/t/smoothing-causes-offset-of-portion-of-copied-segment/21340/2 "2022-01-07T22:48:25Z")

</div>

Are the voxels isotropic?  
Ideas for investigation:

- What happens if you resample segmentation in this region to a higher resolution?
- What happens if you draw or paint in thin structures in different orientations? Is the displacement always present and in a consistent direction? For example you could paint in a sphere, hollow it so it is thin shell, and then smooth that and see what orientations lead to displacements.

One idea which comes to mind is that smoothing will tend to shrink convex areas and will tend to expand concave areas, so that could explain some net motion of a structure which is concave on one side and convex on the opposite side. However, this wouldn’t explain why two identical objects would become displaced from one another due to smoothing.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [January 8, 2022, 7:47pm UTC](https://discourse.slicer.org/t/smoothing-causes-offset-of-portion-of-copied-segment/21340/3 "2022-01-08T19:47:32Z")

</div>

That looks to me like a bug in the smoothing. Can you reproduce it on a simpler structure?

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [January 12, 2022, 12:27pm UTC](https://discourse.slicer.org/t/smoothing-causes-offset-of-portion-of-copied-segment/21340/4 "2022-01-12T12:27:03Z")

</div>

Thanks for the ideas!

Voxels are isotropic. I’ll work on getting an example using a simpler structure.

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [January 17, 2022, 6:00pm UTC](https://discourse.slicer.org/t/smoothing-causes-offset-of-portion-of-copied-segment/21340/5 "2022-01-17T18:00:00Z")

</div>

I think I have an example that shows the issue in a simpler structure using demo data. There are two segments, a large green one and a smaller red one that is a copy of part of the large green one. When you hide/show the segments, you can see a small shift in position of the smaller red one. It is not to the same degree as the example I showed above, this is possibly due to differences in resolution - MRHead is much lower res than the micro-CT scan from my original image.

Dropbox link to MRB file below.

Any ideas and suggestions would be most welcome! Thanks!!

-Hollister

> **[Slicer-smoothing-issue](https://www.dropbox.com/sh/mvcb32vfe8zmqco/AADja_YzPM2ju-QPthZ2l1VNa?dl=0)**
>
> Shared with Dropbox

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [January 17, 2022, 8:25pm UTC](https://discourse.slicer.org/t/smoothing-causes-offset-of-portion-of-copied-segment/21340/6 "2022-01-17T20:25:59Z")

</div>

For issues like this I have always used a little 10x10x10 voxel image with some segmentation. You can find it in the SampleData module, it’s called TinyPatient. The shift will be very obvious if it’s there.

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [January 18, 2022, 7:14pm UTC](https://discourse.slicer.org/t/smoothing-causes-offset-of-portion-of-copied-segment/21340/7 "2022-01-18T19:14:23Z")

</div>

Is there a component of the smoothing algorithm which takes into account the total size of the object to be smoothed? If, for example, the bounding box size were used to normalize something, the bounding box size is quite different in both these cases.

If I turn off all smoothing on the segments @hherhold generated, the surface renderings look identical (as they should). At other smoothing factors, there are definite, but small, shifts between the surfaces. The error may show up as an error in physical dimensions or in voxel dimensions, so it makes sense to play with both of those. I’ll take a look at TinyPatient if I get a chance.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [January 18, 2022, 7:32pm UTC](https://discourse.slicer.org/t/smoothing-causes-offset-of-portion-of-copied-segment/21340/8 "2022-01-18T19:32:40Z")

</div>

I’ve seen things like this happen in the past when data is resampled but a shift in the origin is not taken into account. Since, like DICOM, our origin is in the center of a voxel and not the corner, the origin is shifted when we resample the images to a different spacing without changing the physical size of the image bounds.

---

<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:** [January 18, 2022, 11:03pm UTC](https://discourse.slicer.org/t/smoothing-causes-offset-of-portion-of-copied-segment/21340/9 "2022-01-18T23:03:07Z")

</div>

As @mikebind suspected, the `vtkWindowedSincPolyDataFilter` normalizes coordinates (rescales the input to a unit cube if `NormalizeCoordinates` is enabled; which it is), therefore the smoothing result depends on the bounding box size. In general, the difference should be negligible, but it seems that it is possible to see a perceivable shift in real-world applications where the ROI size is very different along the 3 axes.

Disabling coordinates normalization fixes the issue, but I’ll need to check with Will Schroeder (developer of this algorithm) what other issues it may cause if we skip normalization.

---

<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:** [January 18, 2022, 11:36pm UTC](https://discourse.slicer.org/t/smoothing-causes-offset-of-portion-of-copied-segment/21340/10 "2022-01-18T23:36:01Z")

</div>

Question posted to the VTK forum:

> **[Slight offset in vtkWindowedSincPolyDataFilter if normalization is enabled](https://discourse.vtk.org/t/slight-offset-in-vtkwindowedsincpolydatafilter-if-normalization-is-enabled/7676)**
>
> When using vtkWindowedSincPolyDataFilter with NormalizeCoordinates enabled then we have found that smoothing result is slightly shifted when the bounding box of the mesh is changed. Example Data set:...

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [January 19, 2022, 12:46am UTC](https://discourse.slicer.org/t/smoothing-causes-offset-of-portion-of-copied-segment/21340/11 "2022-01-19T00:46:07Z")

</div>

Thank you very much!
