# Calculate harmonic energy of displacement vector field (DVF)

**URL:** <https://discourse.slicer.org/t/calculate-harmonic-energy-of-displacement-vector-field-dvf/5211>\
**Category:** Support\
**Tags:** registration\
**Created:** [December 28, 2018, 12:06pm UTC](https://discourse.slicer.org/t/calculate-harmonic-energy-of-displacement-vector-field-dvf/5211 "2018-12-28T12:06:24Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![11118](https://avatars.discourse-cdn.com/v4/letter/1/7993a0/32.png) [@11118](https://discourse.slicer.org/u/11118)\
**Post date:** [December 28, 2018, 12:06pm UTC](https://discourse.slicer.org/t/calculate-harmonic-energy-of-displacement-vector-field-dvf/5211/1 "2018-12-28T12:06:25Z")

</div>

After registration produces DVF, how to use 3Dslicer to calculate its jacobian and harmonic energy.Just like the evaluation framework in this article:A framework for deformable image registration validation in radiotherapy clinical applications.I can’t find this function?

---

<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:** [December 29, 2018, 3:08pm UTC](https://discourse.slicer.org/t/calculate-harmonic-energy-of-displacement-vector-field-dvf/5211/2 "2018-12-29T15:08:38Z")

</div>

Sliver has several modules for qualitative, quantitative, and clinical application specific evaluation of registration.

- Qualitative: [Transforms](https://www.slicer.org/wiki/Documentation/Nightly/Modules/Transforms#Transform_display_options) module offers rich visualization of transforms in slice and 3D views.
- Anatomical metric - Hausdorff distance and Dice similarity coefficient: [Segment comparison](https://www.slicer.org/wiki/Documentation/Nightly/Modules/SegmentComparison) module in SlicerRT
- Dose metrics - [Dose comparison](https://www.slicer.org/wiki/Documentation/Nightly/Modules/DoseComparison), [Dose volume histogram metrics](https://www.slicer.org/wiki/Documentation/Nightly/Modules/DoseVolumeHistogram), [Dose volume histogram comparison](https://github.com/SlicerRt/SlicerRT/tree/master/DvhComparison) modules in SlicerRT extension
- Generic registration quality assurance: [https://github.com/gsi-biomotion/SlicerRegistrationQA/blob/master/Documentation.md](https://github.com/gsi-biomotion/SlicerRegistrationQA/blob/master/Documentation.md)
- You can also compute various custom metrics using Python (numpy, etc.) in Slicer’s Python console, [Slicer Jupyter notebook](https://github.com/Slicer/SlicerJupyter), or by adding a scripted module

If there are any additional metrics described in “A framework for deformable image registration validation in radiotherapy clinical applications” paper that you cannot find in Slicer then please contact the authors and ask them how to access those methods and report back to us. We can then help in getting those methods available in current version of Slicer.

---

<div class="post-metadata">

**Author:** ![11118](https://avatars.discourse-cdn.com/v4/letter/1/7993a0/32.png) [@11118](https://discourse.slicer.org/u/11118)\
**Post date:** [December 30, 2018, 9:16am UTC](https://discourse.slicer.org/t/calculate-harmonic-energy-of-displacement-vector-field-dvf/5211/3 "2018-12-30T09:16:48Z")

</div>

thank you very much,I found the Jacobian but I can not found harmonic energy of DVF,

---

<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:** [December 30, 2018, 2:01pm UTC](https://discourse.slicer.org/t/calculate-harmonic-energy-of-displacement-vector-field-dvf/5211/4 "2018-12-30T14:01:59Z")

</div>

I’m not sure if harmonic energy has any clinically relevant meaning and it is not commonly used, so you not miss much by not computing it. If you want the value anyway then contact the authors of the paper that you referred to above.

---

<div class="post-metadata">

**Author:** ![11118](https://avatars.discourse-cdn.com/v4/letter/1/7993a0/32.png) [@11118](https://discourse.slicer.org/u/11118)\
**Post date:** [January 2, 2019, 12:06pm UTC](https://discourse.slicer.org/t/calculate-harmonic-energy-of-displacement-vector-field-dvf/5211/5 "2019-01-02T12:06:37Z")

</div>

Thank you very much for your suggestion. Maybe I can take advantage of other features of DVF and give up one to find a more clinically available feature.

---

<div class="post-metadata">

**Author:** ![labixin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/labixin/32/1965_2.png) [@labixin](https://discourse.slicer.org/u/labixin)\
**Post date:** [August 22, 2019, 2:49am UTC](https://discourse.slicer.org/t/calculate-harmonic-energy-of-displacement-vector-field-dvf/5211/6 "2019-08-22T02:49:22Z")

</div>

Hi all,

I am now doing quantitative evaluation of registration and I plan to use three categories of metrics.

1. Segment comparison: Hausdorff distance and Dice similarity coefficient
2. Deformation vector field: Jacobian determinant
3. Anatomical landmarks: Target registration error

I could’t find where to calculate TRE. I wonder if the [Fiducial registration wizard module](https://discourse.slicer.org/t/evaluating-registration-error/3091/4) is similar to the TRE calculation.

Besides, is the Jacobian calculated within “RegistrationQA” module (Sorry but I couldn’t find it)? And the module can’t be installed using the latest Slicer preview version? (The log is shown below)

Hope for some suggestions. Thanks.

> **Error Log**
>
> Traceback (most recent call last):  
> File “”, line 1, in   
> File “D:\Slicer 4.11.0-2019-08-13\lib\Python\Lib\imp.py”, line 170, in load\_source  
> module = \_exec(spec, sys.modules[name])  
> File “”, line 618, in \_exec  
> File “”, line 674, in exec\_module  
> File “”, line 781, in get\_code  
> File “”, line 741, in source\_to\_code  
> File “”, line 219, in \_call\_with\_frames\_removed  
> File “C:/Users/Administrator/AppData/Roaming/NA-MIC/Extensions-28438/RegistrationQA/lib/Slicer-4.11/qt-scripted-modules/CreateRegistrationHierarchy.py”, line 294  
> except Exception, e:  
> ^  
> SyntaxError: invalid syntax  
> loadSourceAsModule - Failed to load file “C:/Users/Administrator/AppData/Roaming/NA-MIC/Extensions-28438/RegistrationQA/lib/Slicer-4.11/qt-scripted-modules/CreateRegistrationHierarchy.py” as module “CreateRegistrationHierarchy” !  
> Fail to instantiate module “CreateRegistrationHierarchy”  
> The following modules failed to be instantiated:  
> CreateRegistrationHierarchy

Crayon

---

<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:** [August 22, 2019, 6:45pm UTC](https://discourse.slicer.org/t/calculate-harmonic-energy-of-displacement-vector-field-dvf/5211/7 "2019-08-22T18:45:59Z")

</div>

> [@labixin](#):
>
> And the module can’t be installed using the latest Slicer preview version? (The log is shown below)

The module seem to use some Python2 syntax that is not compatible with Python3. It would be great if you could give it a go and make the changes (e.g., `except Exception as e` instead `except Exception, e`) and submit a pull request. If you have trouble fixing all the issues then let us know.

> [@labixin](#):
>
> I could’t find where to calculate TRE. I wonder if the [Fiducial registration wizard module](https://discourse.slicer.org/t/evaluating-registration-error/3091/4) is similar to the TRE calculation.

Fiducial registration wizard computes TRE (as RMS of the distance between fixed points and transformed moving points).

---

<div class="post-metadata">

**Author:** ![labixin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/labixin/32/1965_2.png) [@labixin](https://discourse.slicer.org/u/labixin)\
**Post date:** [August 24, 2019, 1:23pm UTC](https://discourse.slicer.org/t/calculate-harmonic-energy-of-displacement-vector-field-dvf/5211/8 "2019-08-24T13:23:14Z")

</div>

Thanks for your reply. Sorry but I am not familiar with python programming. Could you explain more about how to do that? Thanks a lot!

Besides, I have downloaded an early version of slicer which is compatible with Python2 (Slicer-4.11.0-2019-02-27-win-amd64) and gave it a try. But I still failed to calculate the “Fiducial Distance, Contour Measures, Inverse Consistency” after assigning roles (the Log is shown below). What’s more, when I click the “Jacobian determinant”, the software crashed down (showing something wrong with the vtkSlicerRegistrationQAModuleLogic.dll)? Is there something wrong with the module? Hope for some advice. Your help is highly appreciated!

> **Log**
>
> Reading RegistrationQA parameter node  
> Reading RegistrationQA parameter node  
> Volumes not set!
> 
> InverseConsist: Can’t calculate inverse consistency!
> 
> CalculateRegQAFrom: Can’t calculate inverse consistency!
> 
> CalculateContourStatistic: No transform or vector!
> 
> CreateTransormFromVector: Volumes not set!
> 
> CalculateFiducialsDistance: Invalid input parameters!
> 
> CalculateRegQAFrom: Cannot calculate Fiducal distance!

Sincerely,

Crayon

---

<div class="post-metadata">

**Author:** ![labixin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/labixin/32/1965_2.png) [@labixin](https://discourse.slicer.org/u/labixin)\
**Post date:** [August 25, 2019, 1:37pm UTC](https://discourse.slicer.org/t/calculate-harmonic-energy-of-displacement-vector-field-dvf/5211/9 "2019-08-25T13:37:09Z")

</div>

Finally I have fixed all the issues with the syntax and succeeded in calculating all the values. And I found that the reason why slicer crashed down and output nothing was the incorrect input (the dvf must be loaded as “volume” but not “transform”). Very useful extension! Thank you all for building and integrating it with slicer.

Crayon

---

<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:** [August 26, 2019, 7:00pm UTC](https://discourse.slicer.org/t/calculate-harmonic-energy-of-displacement-vector-field-dvf/5211/10 "2019-08-26T19:00:42Z")

</div>

Great! I don’t see any pull requests with your changes [here](https://github.com/gsi-biomotion/SlicerRegistrationQA/pulls). Make sure you push all your changes to your fork and submit a pull request to the official repository to make RegistrationQA work for others, too (and to remove the burden of maintenance work from you). Thanks!

---

<div class="post-metadata">

**Author:** ![labixin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/labixin/32/1965_2.png) [@labixin](https://discourse.slicer.org/u/labixin)\
**Post date:** [August 27, 2019, 7:25pm UTC](https://discourse.slicer.org/t/calculate-harmonic-energy-of-displacement-vector-field-dvf/5211/11 "2019-08-27T19:25:29Z")

</div>

Hi,

I have submitted a pull request with my changes. I’m glad that I could ever make some contributions (never before).

Besides, I have a question relating to the evaluation of Jacobian determinant. I have registered two ct images which have different voxel intensities of ROI because of tumor resection and post-surgical changes. I wonder how to quantify the impact of intensity variation? Could the jacobian metric indicate something? (I am not sure about the interpretation of jacobian) Hope for some suggestions. Thank you!

Sincerely,  
Crayon

---

<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:** [August 28, 2019, 2:56pm UTC](https://discourse.slicer.org/t/calculate-harmonic-energy-of-displacement-vector-field-dvf/5211/12 "2019-08-28T14:56:42Z")

</div>

> [@labixin](#):
>
> I have submitted a pull request with my changes.

Could you please post the link to the pull request (just to make sure it is merged)?

> [@labixin](#):
>
> I’m glad that I could ever make some contributions (never before).

We are glad, too, congratulations! 🍾

> [@labixin](#):
>
> I have registered two ct images which have different voxel intensities of ROI because of tumor resection and post-surgical changes. I wonder how to quantify the impact of intensity variation? Could the jacobian metric indicate something?

Usually when there is no correspondence between two images (instrument is visible in an intra-procedural image, tumor is not visible in post-procedural image, etc.) then you mask out that region in the images to make sure you don’t introduce any errors by trying to match unrelated things. These masked regions probably have to be excluded from further analysis, too.

---

<div class="post-metadata">

**Author:** ![labixin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/labixin/32/1965_2.png) [@labixin](https://discourse.slicer.org/u/labixin)\
**Post date:** [September 2, 2019, 3:16am UTC](https://discourse.slicer.org/t/calculate-harmonic-energy-of-displacement-vector-field-dvf/5211/13 "2019-09-02T03:16:04Z")

</div>

Thanks for your extended help. I will focus more on the related things. Besides, here is the link [pull request](https://github.com/crayonxx/SlicerRegistrationQA).

Crayon

---

<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:** [September 4, 2019, 2:30pm UTC](https://discourse.slicer.org/t/calculate-harmonic-energy-of-displacement-vector-field-dvf/5211/14 "2019-09-04T14:30:08Z")

</div>

Thank you, I’ve found the updated file that you uploaded. It is not a “pull request” just an upload to your forked version of the repository, so the original author was not notified. I’ve created a pull request now (see [here](https://github.com/gsi-biomotion/SlicerRegistrationQA/pulls)), so your changes will hopefully get into the official version soon.

---

<div class="post-metadata">

**Author:** ![labixin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/labixin/32/1965_2.png) [@labixin](https://discourse.slicer.org/u/labixin)\
**Post date:** [September 5, 2019, 8:00am UTC](https://discourse.slicer.org/t/calculate-harmonic-energy-of-displacement-vector-field-dvf/5211/15 "2019-09-05T08:00:11Z")

</div>

Thank you for keep following. I have checked that the pull request is now merged. Sorry that I forgot to pull request in the original repository. Thanks again for all your efforts in building slicer! 🙂

Crayon

---

<div class="post-metadata">

**Author:** ![labixin](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/labixin/32/1965_2.png) [@labixin](https://discourse.slicer.org/u/labixin)\
**Post date:** [October 12, 2020, 2:50pm UTC](https://discourse.slicer.org/t/calculate-harmonic-energy-of-displacement-vector-field-dvf/5211/16 "2020-10-12T14:50:42Z")

</div>

Hi all,

I’m using Registration QA extension to calculate the Jacobian Determinant. I want to calculate it within specific segment (from Segmentation Module). The “Create ROI around segments” button could create a rectangular box around segment. However it’s not so conformal. How could I implement this? Where could I modify the source code?

Hope for some suggestions. Thanks a lot!

Crayon
