# Registrations errors (Root square mean & joint histogram)

**URL:** https://discourse.itk.org/t/registrations-errors-root-square-mean-joint-histogram/3095
**Category:** Beginner Questions
**Tags:** simpleitk, registration, python
**Created:** [May 19, 2020, 11:58pm UTC](https://discourse.itk.org/t/registrations-errors-root-square-mean-joint-histogram/3095 "2020-05-19T23:58:39Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Dodox](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/ec9cab/32.png) [@Dodox](https://discourse.itk.org/u/Dodox)
#### Post date: [May 19, 2020, 11:58pm UTC](https://discourse.itk.org/t/registrations-errors-root-square-mean-joint-histogram/3095/1 "2020-05-19T23:58:40Z")

</div>

Hello everyone,

I would like to know if there is a function on SimpleITK for Python which calculates RMS and joint histogram.

cordially.

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [May 20, 2020, 1:08am UTC](https://discourse.itk.org/t/registrations-errors-root-square-mean-joint-histogram/3095/2 "2020-05-20T01:08:11Z")

</div>

Hello @Dodox,  
Unfortunately, no, but these can be readily implemented in Python:

```auto
import SimpleITK as sitk
import matplotlib.pyplot as plt
import numpy as np

# Resample one image onto the other so that we compare the relevant pixels
# Also note we are reading them as float32
img1 = sitk.ReadImage('training_001_ct.mha', sitk.sitkFloat32)
img2 = sitk.ReadImage('training_001_mr_T1.mha', sitk.sitkFloat32)
img2_resampled = sitk.Resample(img2,img1)

# Compute RMSE using numpy, note if the original images are not in floating
# point you may have overflow related errors (int16 may suffer from overlow
# when some values are squared)
arr1 = sitk.GetArrayViewFromImage(img1)
arr2 = sitk.GetArrayViewFromImage(img2_resampled)
RMSE = np.sqrt(np.sum((arr1 - arr2)**2)/np.prod(arr1.shape))
print(RMSE)

# Use matplotlib for 2D histogram
plt.figure()
plt.hist2d(arr1.ravel(), arr2.ravel());
plt.show()

```

---

<div class="post-metadata">

### Author: ![Dodox](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/ec9cab/32.png) [@Dodox](https://discourse.itk.org/u/Dodox)
#### Post date: [May 20, 2020, 1:11am UTC](https://discourse.itk.org/t/registrations-errors-root-square-mean-joint-histogram/3095/3 "2020-05-20T01:11:54Z")

</div>

Thank you very much \<3 @zivy
