# Transforme segmentaion

**URL:** https://discourse.slicer.org/t/transforme-segmentaion/29150
**Category:** Support
**Tags:** segmentation, dicom
**Created:** [April 26, 2023, 8:31pm UTC](https://discourse.slicer.org/t/transforme-segmentaion/29150 "2023-04-26T20:31:42Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Thirawat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/thirawat/32/65667_2.png) [@Thirawat](https://discourse.slicer.org/u/Thirawat)
#### Post date: [April 26, 2023, 8:31pm UTC](https://discourse.slicer.org/t/transforme-segmentaion/29150/1 "2023-04-26T20:31:42Z")

</div>

I annotated a big dataset (for me), but the Dicom file of the CT scan has transformed (I get this from start).  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/1/419e1112319f6bddf5fc398bcd536314b330144c.png)

when I [use this segment in Python by simpleITK [The problem post]](https://discourse.slicer.org/t/reads-dcm-volume-with-grid-transform-with-python/28998) it will not match with the CT image because the CT image that simpleITK can read is raw Dicom file not Dicom transformed.

so I want to fix this problem by doing something with the segment after trying to do something with Dicom.  
but I can’t find a way to transform segmentation.

Thank you.  
Thirawat

---

<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: [April 26, 2023, 8:47pm UTC](https://discourse.slicer.org/t/transforme-segmentaion/29150/2 "2023-04-26T20:47:45Z")

</div>

The [acquisition transform](https://slicer.readthedocs.io/en/latest/user_guide/modules/dicom.html#basic-usage) accounts for irregularity in the spacing and other [issues with the geometry](https://github.com/Slicer/Slicer/commit/3328b81211cb2e9ae16a0b49097744171c8c71c0). You can right click on the icon in the transform column and pick the “Harden transform” option to resample. You probably want also apply the transform and harden the segmentation.

---

<div class="post-metadata">

### Author: ![Thirawat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/thirawat/32/65667_2.png) [@Thirawat](https://discourse.slicer.org/u/Thirawat)
#### Post date: [April 26, 2023, 9:59pm UTC](https://discourse.slicer.org/t/transforme-segmentaion/29150/3 "2023-04-26T21:59:42Z")

</div>

**I think this way will work.**  
I try on one Dicaom and on Segment  
**but** when ‘Harden transform’ on Dicom some side of the image is out of ‘View Box’, and some side do not reach the side of the box. then when I read it the shape is (80, 613, 512)

for more context, I draw a little thing.  
**How to crop this?**

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/0/b08f59c6875955f134509bbd193e1c9904625382.png)

**[Edit]**  
First CT Dicom shape → (82, 512, 512)  
Segment shape → (82, 512, 512)  
CT Dicom Harden transform’ shape → (80, 613, 512)

Need to fix:

1. missing slide
2. crop slide in to Box

---

<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: [April 26, 2023, 10:48pm UTC](https://discourse.slicer.org/t/transforme-segmentaion/29150/4 "2023-04-26T22:48:10Z")

</div>

Probably you can use CropVolume for this. If you can sort it out please include some screenshots to illustrate what’s not working for you.

---

<div class="post-metadata">

### Author: ![Thirawat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/thirawat/32/65667_2.png) [@Thirawat](https://discourse.slicer.org/u/Thirawat)
#### Post date: [April 28, 2023, 4:31am UTC](https://discourse.slicer.org/t/transforme-segmentaion/29150/5 "2023-04-28T04:31:46Z")

</div>

Thank you very much now I find a way to manage with this problem.

my problem: Creating a segmentation dataset with CT has transformed. but Python cant read the CT transform and can only read raw CT.

so I solve it by creating an inverted transform segmentation.  
for more details:

- I have CT .dcm with transformed. and have segmentation nrrd.
- Import segmentation as volume.
- Clone transform form CT to segmentation volume.
- Invert transform and Edit properties to apply to segmentation volume.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/f/3f860f6198cc3cbf0419739e4043978744152989.png)
- then “Harden transform” segmentation.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/2/02fb00f97f50d5c20cd3962c52d4a263b3b32d8a.png)  
and save it as dicom.

for the shape problem that will change I slove in Python (just cut it off):

```auto
# read dicom filse (CT, mask)
ct_image_array = readCT(dir_ct_paths[n])
label_image_array = readLabel(dir_label_paths[n])

# preprocess mass
label_image_array = label_image_array[:ct_image_array.shape[0], :512, :512]

```
