# Transform a labelmap with a transorm and save it

**URL:** <https://discourse.slicer.org/t/transform-a-labelmap-with-a-transorm-and-save-it/25640>\
**Category:** Support\
**Created:** [October 11, 2022, 9:19am UTC](https://discourse.slicer.org/t/transform-a-labelmap-with-a-transorm-and-save-it/25640 "2022-10-11T09:19:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![S\_Arbabi](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@S\_Arbabi](https://discourse.slicer.org/u/S_Arbabi)\
**Post date:** [October 11, 2022, 9:19am UTC](https://discourse.slicer.org/t/transform-a-labelmap-with-a-transorm-and-save-it/25640/1 "2022-10-11T09:19:30Z")

</div>

Hi,

I have a labelmap and I’m transforming it using a transform node:

`lblmap_node.SetAndObserveTransformNodeID(transform_node.GetID())`

but then when I save this labelmap\_node and open it later it seems like it hasn’t been transformed:

`slicer.util.saveNode(lblmap_node, path)`

I’ve seen threads here about hardening the transform, or exporting the node in the world coordinate system. I finally extract the segmentation out of labelmap, apply the transform of segmentation node and convert it into labelmap again:

```auto
segmentation_node.SetAndObserveTransformNodeID(transform_node.GetID())
slicer.modules.segmentations.logic().ExportVisibleSegmentsToLabelmapNode(segmentationNode, segmentationLblmap, reference_volume_node)

```

It works but weiredly it cuts an area of labelmap shown in the image bellow:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/6/e69ac6006acc47e277ae70e7c2619ed1aff27521.png)  
instead of being like this:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/3/f3eca50e87e13378f996cc329fa27d84cb60cda6.png)

Am I missing something here? I appreciate any suggestions.

Best,  
Saeed

---

<div class="post-metadata">

**Author:** ![S\_Arbabi](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@S\_Arbabi](https://discourse.slicer.org/u/S_Arbabi)\
**Post date:** [October 12, 2022, 8:02am UTC](https://discourse.slicer.org/t/transform-a-labelmap-with-a-transorm-and-save-it/25640/2 "2022-10-12T08:02:08Z")

</div>

I found the solution to this using transformableNode.HardenTransform().  
But my question is why the shape changes after hardenning the transform? in my case the shape of fixed image is 135x300x177 and shape of moving labelmap before transfer is 135x300x189, but after setAndObserveTransform and hardening transform its shape is 141x308x192. which is something I don’t understand!!

---

<div class="post-metadata">

**Author:** ![S\_Arbabi](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@S\_Arbabi](https://discourse.slicer.org/u/S_Arbabi)\
**Post date:** [October 12, 2022, 12:17pm UTC](https://discourse.slicer.org/t/transform-a-labelmap-with-a-transorm-and-save-it/25640/3 "2022-10-12T12:17:55Z")

</div>

Resample Scalar Volume worked.  
[https://discourse.slicer.org/t/resample-scalar-volumes-scripting-in-python/19736/11?u=s\_arbabi](https://discourse.slicer.org/t/resample-scalar-volumes-scripting-in-python/19736/11)
