SetInitialDisplacementField not working properly for MultiResolutionPDEDeformableRegistration

I’m attempting to perform diffeomorphic demons registration of two images using the corresponding filter and the MultiResolutionPDEDeformableRegistration class. I compute an affine transform of the the two images beforehand to register them to the same physical space and create a displacement field using this transform. Then I use this field as the initial displacement field to the MultiResolutionPDEDeformableRegistration object. However, upon running the code I get the following error:

itk::ExceptionObject (0x1231130)
Location: "void itk::ImageToImageFilter<TInputImage, TOutputImage>::VerifyInputInformation() [with TInputImage = itk::Image<itk::Vector<float, 3u>, 3u>; TOutputImage = itk::Image<itk::Vector<float, 3u>, 3u>]" 
File: /home/parallels/Desktop/Slicer-SuperBuild/ITKv4/Modules/Core/Common/include/itkImageToImageFilter.hxx
Line: 241
Description: itk::ERROR: DiffeomorphicDemonsRegistrationFilter(0x13870b0): Inputs do not occupy the same physical space! 
InputImage Origin: [7.9639916e+01, -1.1042095e+02, -1.0426932e+02], InputImageMovingImage Origin: [-8.8678563e+01, -1.4923204e+02, 1.2193930e+02]
    Tolerance: 1.5000000e-05
InputImage Spacing: [1.5000000e+01, 1.5000000e+01, 1.9199951e+01], InputImageMovingImage Spacing: [1.5154560e+01, 1.5108180e+01, 1.9319538e+01]
    Tolerance: 1.5000000e-05
InputImage Direction: 1.5926319e-08 1.4070701e-08 -1.0000000e+00
9.9237583e-01 -1.2324859e-01 1.4070700e-08
1.2324859e-01 9.9237583e-01 1.5926320e-08
, InputImageMovingImage Direction: -0.0000000e+00 5.5205551e-10 1.0000000e+00
5.5205551e-10 1.0000000e+00 -5.5205553e-10
-1.0000000e+00 5.5205551e-10 0.0000000e+00

    Tolerance: 1.0000000e-06

I’ve figured out that the error arises because the affine transform is not being applied before the demons registration takes place. I double checked that this is true by commenting out the code where the initial displacement field is applied. I end up getting the exact same error. Additionally, when I apply the affine transform to the input before running the demons registration, it works error free.

I’m using the following file as the base for the code I’m creating so it can act as a good approximate of what I’m trying to accomplish. Been working on this issue for a while and would really appreciate any advice.

Is this problem solved for you? Im working on the same code and got stuck at the same error.