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.

I am working on multiscale_demons registration and getting the following error from this line here: 66_Registration_Demons

Error:

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

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:

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:

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

Additional print statement:

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

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.


And this happened so many times for many other pages during troubleshoot.

Any help?

Hello @banikr,

Not sure what the problem was with the link to the Image Documentation, 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?

imagesforzivy.h5 (163.3 KB)

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

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.