# RuntimeError: Exception thrown in SimpleITK Image\_CopyInformation: /tmp/SimpleITK/Code/Common/src/sitkImage.cxx:278: sitk::ERROR: Source Image for information does not match this image's dimension.

**URL:** https://discourse.itk.org/t/runtimeerror-exception-thrown-in-simpleitk-image-copyinformation-tmp-simpleitk-code-common-src-sitkimage-cxx-sitk-source-image-for-information-does-not-match-this-images-dimension/5787
**Category:** Uncategorized
**Created:** [March 8, 2023, 9:24pm UTC](https://discourse.itk.org/t/runtimeerror-exception-thrown-in-simpleitk-image-copyinformation-tmp-simpleitk-code-common-src-sitkimage-cxx-sitk-source-image-for-information-does-not-match-this-images-dimension/5787 "2023-03-08T21:24:53Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![banikr](https://discourse.itk.org/user_avatar/discourse.itk.org/banikr/32/3296_2.png) [@banikr](https://discourse.itk.org/u/banikr)
#### Post date: [March 8, 2023, 9:24pm UTC](https://discourse.itk.org/t/runtimeerror-exception-thrown-in-simpleitk-image-copyinformation-tmp-simpleitk-code-common-src-sitkimage-cxx-sitk-source-image-for-information-does-not-match-this-images-dimension/5787/1 "2023-03-08T21:24:53Z")

</div>

I am working on `multiscale_demons` registration and getting the following error from this line here: [66\_Registration\_Demons](http://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/Python_html/66_Registration_Demons.html#:~:text=initial_displacement_field.CopyInformation(fixed_images%5B%2D1%5D))

Error:

```auto
Traceback (most recent call last):
  File "/home/banikr/PycharmProjects/registration/RegistrationWoMorph.py", line 357, in <module>
    initial_displacement_field.CopyInformation(fixed_images[-1])
  File "/home/banikr/miniconda3/envs/reg37/lib/python3.7/site-packages/SimpleITK/SimpleITK.py", line 3446, in CopyInformation
    return _SimpleITK.Image_CopyInformation(self, srcImage)
RuntimeError: Exception thrown in SimpleITK Image_CopyInformation: /tmp/SimpleITK/Code/Common/src/sitkImage.cxx:278:
sitk::ERROR: Source Image for information does not match this image's dimension.

```

If I print the fixed\_image

```auto
print("low res image >> ", fixed_images[-1].GetDimension())
low res image >> 2

```

which is a 2D image that I am using.  
I tried adding the following:

```auto
initial_displacement_field = sitk.Image(fixed_images[-1].GetWidth(),
                                        fixed_images[-1].GetHeight(),
                                        fixed_images[-1].GetDepth(),
                                        fixed_images[-1].GetDimension(),
                                        # sitk.sitkVectorFloat64
                                        )

```

which didn’t work.  
The following params are being used:

```auto
shrinkFactors = [4, 2, 1]
smoothingSigmas = [8, 4, 0.000000001]

```

Additional print statement:

```auto
fixed & moving image size >> 0 : (111, 93) (111, 93)
1 : (111, 93) == (111, 93)
2 : (56, 47) == (56, 47)
3 : (28, 23) == (28, 23)

```

After smooth and shrink the `fixed_images[-1]` looks like:  
 ![image](https://discourse.itk.org/uploads/default/original/2X/5/501a4ccd84cbf9919a04dde80f0978f15f8bbc9d.png)

Also as a side issue the online sources documention for itk seems not to work. for example I wanted to check `sitk.Image` documentation to learn more about `CopyInformation()`  
The page won’t simply load.

 ![image](https://discourse.itk.org/uploads/default/original/2X/d/da88074277bed461c8153423c2c678d72de0e17b.png)  
And this happened so many times for many other pages during troubleshoot.

Any help?

---

<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: [March 9, 2023, 5:17pm UTC](https://discourse.itk.org/t/runtimeerror-exception-thrown-in-simpleitk-image-copyinformation-tmp-simpleitk-code-common-src-sitkimage-cxx-sitk-source-image-for-information-does-not-match-this-images-dimension/5787/2 "2023-03-09T17:17:37Z")

</div>

Hello @banikr,

Not sure what the problem was with the link to the [Image Documentation](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1Image.html), works now. Possibly intermittent connectivity issues?

With respect to the error, not enough information to judge, but guessing here. Is it possible that the 2D image is actually a 3D image? `GetDepth()` returns 0 and `GetDimension()` returns 3 and not 2 as expected. Can you share an image example so that we get a better understanding of the image characteristics?

---

<div class="post-metadata">

### Author: ![banikr](https://discourse.itk.org/user_avatar/discourse.itk.org/banikr/32/3296_2.png) [@banikr](https://discourse.itk.org/u/banikr)
#### Post date: [March 10, 2023, 12:06am UTC](https://discourse.itk.org/t/runtimeerror-exception-thrown-in-simpleitk-image-copyinformation-tmp-simpleitk-code-common-src-sitkimage-cxx-sitk-source-image-for-information-does-not-match-this-images-dimension/5787/3 "2023-03-10T00:06:51Z")

</div>

[imagesforzivy.h5](https://discourse.itk.org/uploads/short-url/moRWFZA8NUHhUmOjFZN1fThh6Ea.h5) (163.3 KB)

Hello @zivy  
I have uploaded both matrices of fixed and moving images. The following should access those:

```auto
dataFold = path to where the h5py downloaded
saveSegPath = os.path.join(dataFold, 'imagesforzivy.h5')

with h5py.File(saveSegPath, 'r') as pfile:
    fixed_array = np.array(pfile['fixed_image'])
    moving_array = np.array(pfile['moving_image'])

```

Also I checked the `fixed_images[-1].GetDepth()` which shows 0.
