# Masking STL for Registration

**URL:** <https://discourse.slicer.org/t/masking-stl-for-registration/5725>\
**Category:** Support\
**Created:** [February 11, 2019, 2:42pm UTC](https://discourse.slicer.org/t/masking-stl-for-registration/5725 "2019-02-11T14:42:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![miniBin](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@miniBin](https://discourse.slicer.org/u/miniBin)\
**Post date:** [February 11, 2019, 2:42pm UTC](https://discourse.slicer.org/t/masking-stl-for-registration/5725/1 "2019-02-11T14:42:41Z")

</div>

Hello I need to do registration on a stl of a vessel but I only need to deform part of the stl because I need the top and bottom of it to be flat. Here is a picture ![vessel](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/c/fc923c385a09779108d5df123b5838e4235ae5a2.png)

I think I can use masking but I’m not sure how? I need to make sure that the top and bottom of the vessel are flat. Thank you.

---

<div class="post-metadata">

**Author:** ![miniBin](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@miniBin](https://discourse.slicer.org/u/miniBin)\
**Post date:** [February 12, 2019, 2:53pm UTC](https://discourse.slicer.org/t/masking-stl-for-registration/5725/2 "2019-02-12T14:53:26Z")

</div>

My procedure is…

FixedFrame = FrameA  
MovingFrame = FrameB

Use ElastiX so FrameB gets transformed into FrameA space.  
Change transform to Volume.  
Mask Transform Volume with Frame B segment.  
Import Masked Transform Volume as Transform.  
Apply Transform to FrameB stl.

I do it with masked vs. no mask transform and the results look different?

Frame B stl:  
 ![frameB](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/8/e8a63402839fb123f60e3773ad0b5a77975be5cd.png)

Resulting stl from non-masked transform (gray)  
Resulting stl from masked transform (pink)

 ![result](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/4/048a36bc2774ad2e686482d1c56a1b737c5e06b7.png)

Why is there a difference between masked vs non-masked? Shouldn’t the transform only apply to the stl? I am currently masking the transform so I don’t have to deal with all the other data, but shouldn’t it have the same effect on the stl as the non-masked transform?

Sorry if this does not make sense. I can try to explain more.

---

<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:** [February 13, 2019, 7:51pm UTC](https://discourse.slicer.org/t/masking-stl-for-registration/5725/3 "2019-02-13T19:51:14Z")

</div>

> [@miniBin](#):
>
> I can try to explain more.

Yes, I think you need to provide more context - what are you trying to accomplish?

---

<div class="post-metadata">

**Author:** ![miniBin](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@miniBin](https://discourse.slicer.org/u/miniBin)\
**Post date:** [February 13, 2019, 8:06pm UTC](https://discourse.slicer.org/t/masking-stl-for-registration/5725/4 "2019-02-13T20:06:08Z")

</div>

Hello and thank you for your reply.

I am trying to transform only part of a stl geometry. I want the other part not to be transformed (1 mm down from the top).

Example picture:  
 ![scenario](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/a/3a7c912dc02c4164f22b8546d9838b24cc783b24.png)

Here is what I have done:

-Create transform from two vessel volumes  
-Import transform as volume  
-Use segment to mask part that I want “static” and set inside to “0”  
-Export masked transform volume  
-import masked transform volume as transform  
-Import STL of segment of vessel  
-Apply transform to STL  
-Harden transform

It seems like the mask is not working.  
The static part does not stay static and it deforms so the top of the vessel is no longer flat like I need it to be.

I am not sure if my transform mask looks right. It is the gray circle but it seems like it still has a gradient and is not masking properly but I set the value to 0?  
 ![maskfail](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/6/a65fbad558f8f3ee9d4c517ead6d8f49cb4832b0.png)

Sorry for the confusion.

---

<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:** [February 13, 2019, 8:19pm UTC](https://discourse.slicer.org/t/masking-stl-for-registration/5725/5 "2019-02-13T20:19:42Z")

</div>

Okay, that helps. At least I think I get it. Did you turn on the arrows or grid features of the transform visualization to confirm that your masked transform is really what you think it is?

---

<div class="post-metadata">

**Author:** ![miniBin](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@miniBin](https://discourse.slicer.org/u/miniBin)\
**Post date:** [February 13, 2019, 8:20pm UTC](https://discourse.slicer.org/t/masking-stl-for-registration/5725/6 "2019-02-13T20:20:48Z")

</div>

![results](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/0/a0d09d8ad034ce95e14f162450586ff4b0b76756.png)

Here is a more detailed image of what is happening.

---

<div class="post-metadata">

**Author:** ![miniBin](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@miniBin](https://discourse.slicer.org/u/miniBin)\
**Post date:** [February 13, 2019, 8:26pm UTC](https://discourse.slicer.org/t/masking-stl-for-registration/5725/7 "2019-02-13T20:26:29Z")

</div>

Yes, I turned the grid on and it is black in those places which is why I am confused. Will update with pics in one second.

---

<div class="post-metadata">

**Author:** ![miniBin](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@miniBin](https://discourse.slicer.org/u/miniBin)\
**Post date:** [February 13, 2019, 8:41pm UTC](https://discourse.slicer.org/t/masking-stl-for-registration/5725/8 "2019-02-13T20:41:30Z")

</div>

Original:  
 ![1](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/1/217bf0a74315bf4db9dafd00bceffce727eae06f.png)

Segment Mask:  
 ![2](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/8/c845e5212fda4223d8bf1331896aa176d881127d.png)

Transform Volume with Mask Applied:  
 ![3](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/f/5f1751388b65c75ff22343d689117bdeddde8446.png)

Parameters used:

 ![parameters](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/6/362ebaf5f8e4fde9e33a761df02b060bd8456c53.png)

Result grid:  
 ![5](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/2/b24a1d34a3225941b0c4ba4db1f96a21c21c8616.png)  
Black is applied mostly to my target area but not all the way?

Transformed stl:  
 ![4](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/d/4d0798c1fb2fb6ccc322b920ac4fea248aed97c8.png)

Masked part was transformed but it wasn’t supposed to be. Arrows show obvious transformation.

One possible error is that my transform has data to transform a much larger geometry (full heart) whereas I am only transforming part of the vessel. When I try to mask a transform to my specific stl shape/segment the result is very jagged and bumpy which is why I use the full transform.

---

<div class="post-metadata">

**Author:** ![miniBin](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@miniBin](https://discourse.slicer.org/u/miniBin)\
**Post date:** [February 13, 2019, 8:59pm UTC](https://discourse.slicer.org/t/masking-stl-for-registration/5725/9 "2019-02-13T20:59:35Z")

</div>

There are a few parts that are being completely ignored.

My mask (tan):  
 ![mymask](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/2/72027e415097957be7d5c0084f750c551810912c.png)

grid result:  
 ![sadness](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/0/107d2edd6d87c47acf6915224d8bf2a3e2f8aa1c.png)

There is a clear green triangle where the mask is being ignored.
