# Arithmetic about apply regularization transform

**URL:** <https://discourse.slicer.org/t/arithmetic-about-apply-regularization-transform/31308>\
**Category:** Development\
**Tags:** dicom\
**Created:** [August 23, 2023, 7:07am UTC](https://discourse.slicer.org/t/arithmetic-about-apply-regularization-transform/31308 "2023-08-23T07:07:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![slicer365](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/slicer365/32/67549_2.png) [@slicer365](https://discourse.slicer.org/u/slicer365)\
**Post date:** [August 23, 2023, 7:07am UTC](https://discourse.slicer.org/t/arithmetic-about-apply-regularization-transform/31308/1 "2023-08-23T07:07:07Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/a/cabe9190b58ef9526bf16ac7412ca5c83d99cbc3.png)  
I am developing an independent software for my clients.

I need this function to correct the data.

The tilt value can be found in Tag,

but how to make changes to the data,

I searched the source code,

but I can’t find the implementation entry for this.

Can anyone help me? Thank you !

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [August 23, 2023, 12:36pm UTC](https://discourse.slicer.org/t/arithmetic-about-apply-regularization-transform/31308/2 "2023-08-23T12:36:35Z")

</div>

> I searched the source code,

If you search for the words `Regularization` and `regularization`, you should be able to identify the relevant files.

Let us know if you sill have issues.

---

<div class="post-metadata">

**Author:** ![slicer365](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/slicer365/32/67549_2.png) [@slicer365](https://discourse.slicer.org/u/slicer365)\
**Post date:** [August 23, 2023, 1:06pm UTC](https://discourse.slicer.org/t/arithmetic-about-apply-regularization-transform/31308/3 "2023-08-23T13:06:55Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/d/edf81c4eb0b50d57797d851f5e13895bf6be121f.png)  
Here is the result ,it seems that there is no what I want.

---

<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:** [August 23, 2023, 1:54pm UTC](https://discourse.slicer.org/t/arithmetic-about-apply-regularization-transform/31308/4 "2023-08-23T13:54:58Z")

</div>

The description and the corresponding source code are here:

> <https://github.com/Slicer/Slicer/commit/3328b81211cb2e9ae16a0b49097744171c8c71c0>
>
> Add a step to the DICOMScalarVolumePlugin to check that the loaded
> volume node's… slice geometry matches what is expected from
> the position and orientation information of the individual
> slices in the DICOM headers.
> 
> If needed, a grid transform is created to reposition each slice
> to the appropriate position in patient space.
> 
> Use an empirically defined epsilon threshold to decide if
> an acquisition transform is needed. The selected value of
> 1e-3 millimeters (one micrometer) is still very small by
> medical imaging standards but is large enough that rounding
> errors and other small variations do not result in extra
> correction transforms when they won't add real value.
> The error is defined as the max absolute difference
> in any coordinate of the corner of any slice so it
> is designed to handle gantry tilt, missing slices,
> and irregularly spaced slices.
> 
> The DICOMReaders self test has been extended to test this in the
> case where slices are missing from the middle of the volume. The
> grid transform results in an interpolated band of pixels using
> information from adjacent slices to 'fill in' for the missing
> data. The test confirms that the last slice of the reconstructed
> volume is in the expected location in patient space. This correction
> means that calculations like ruler or segment statistics can be
> robust even with missing slices.
> 
> Currently the only available testing data is for the case of missing
> slices. However this code should allow proper loading and display of
> several not-uncommon imaging scenarios:
> 
> 1) Missing slices due to network failure or accidental file deletion.
> 
> 2) Gantry tilted image acquisitons (see #4409) which is
> used, for example, to minimize radiation exposure to the retinas
> especially in pediatric imaging.
> 
> 3) Variable table speed during CT acquisition, which is sometimes
> used in abdominal or musculoskeletal imaging to provide high resolution
> in selected body parts and lower resolution between (e.g. high res
> at the ankle, knee and hip, but low res in the shin and thigh).
> 
> Consderations:
> 
> By creating a transform we preserve the original data and leave it
> to the user to resample if desired. The option of resampling
> during load was rejected since it is unclear what sampling grid
> would be best in all cases.
> 
> Although the transform should correct the geometry, a warning dialog is
> still generated during loading since the issue could be correctable
> (such as missing slices) or may be triggered by other data issues
> not forseen by this code.
> 
> Most DICOM data has identical row and column spacing
> but when they do not it's critical to have the right
> spacing geomtry. This code uses the correct definitions
> from the standard. Where PixelSpacing is row/column
> but ImageOrientationPatient if column/row
> 
> We check and avoid ValueError warning when dicom files do not have
> geometry information.
> 
> svn-url: http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=26500
> git-svn-id: http://svn.slicer.org/Slicer4/trunk@26500 3bd1e089-480b-0410-8dfb-8563597acbee

---

<div class="post-metadata">

**Author:** ![slicer365](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/slicer365/32/67549_2.png) [@slicer365](https://discourse.slicer.org/u/slicer365)\
**Post date:** [August 23, 2023, 2:23pm UTC](https://discourse.slicer.org/t/arithmetic-about-apply-regularization-transform/31308/5 "2023-08-23T14:23:37Z")

</div>

Thank you very much ! 👍

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [August 23, 2023, 3:22pm UTC](https://discourse.slicer.org/t/arithmetic-about-apply-regularization-transform/31308/6 "2023-08-23T15:22:54Z")

</div>

> [@jcfr](#):
>
> If you search for the words `Regularization` and `regularization`, you should be able to identify the relevant files.

To complete my previous answer, doing a case-insensitive search returns the following:

```auto
$ rg -i regularization

[...]

Docs/user_guide/modules/dicom.md
186: - Acquisition geometry regularization option supports the creation of a nonlinear transform that corrects for things like missing slices or gantry tilt in the acquisition. See more information [here](https://github.com/Slicer/Slicer/commit/3328b81211cb2e9ae16a0b49097744171c8c71c0)
243:Scanners may create image volumes with varying image slice spacing. Slicer can represent such images in the scene by apply a non-linear transform. To enable this feature, go to menu: Edit / Application settings / DICOM and set *Acquisition geometry regularization* to *apply regularization transform*. Slice view, segmentation, and many other features work directly on non-linearly transformed volumes. For some other features, such as volume rendering, you need to harden the transform on the volume: go to Data module, in the row of the volume node, right-click on the transform column, and choose *Harden transform*.

Modules/Scripted/DICOMLib/DICOMUtils.py
665: # Get acquisition geometry regularization setting value
667: acquisitionGeometryRegularizationEnabled = (settings.value("DICOM/ScalarVolume/AcquisitionGeometryRegularization", "default") != "none")
688: if acquisitionGeometryRegularizationEnabled:
691: warningText += (" If loaded image appears distorted, enable 'Acquisition geometry regularization'"

Modules/Scripted/DICOMPlugins/DICOMScalarVolumePlugin.py
88: " If no regularization is applied then image may appear distorted if it was acquired with irregular geometry.")
90: importFormatsComboBox.addItem(_("default (apply regularization transform)"), "default")
92: importFormatsComboBox.addItem(_("apply regularization transform"), "transform")
96: formLayout.addRow(_("Acquisition geometry regularization:"), importFormatsComboBox)
98: "DICOM/ScalarVolume/AcquisitionGeometryRegularization", importFormatsComboBox,
137: def acquisitionGeometryRegularizationEnabled(self):
139: return (settings.value("DICOM/ScalarVolume/AcquisitionGeometryRegularization", "default") != "none")
542: addAcquisitionTransformIfNeeded=self.acquisitionGeometryRegularizationEnabled())
850: logging.warning(warningText + " Regularization transform is not added, as the option is disabled.")

[...]

```
