Does it have to keep two 3d images has the same spacing and origin when using vtkImageBlend to blend them?

I have 2 3d images ,which have different dimension, origin and spacing ,they both are Grayscale image . When i use volume rendering or put them in 3dSclicer , Their spatial positions match well.
but when i use vtkimageblend to blend them , Their spatial positions dismatch ,i’m not sure the reason.Dose it matter with the image’s dimension,origin or spacing?

this image shows the spatial positions match well
image

this image shows the result of blend , you can see the dismatch from the image
4773685350_53852548431_C16BB2B7-03DA-44f5-B459-9D0CC7FB1B79

Does anyone have any suggestions for me?

The vtkImageBlend filter only considers the Extent. It assumes that the voxels of the two images are already in the same positions. It ignores the spatial position and scale that are defined by the spacing and origin.

Before applying vtkImageBlend, the voxels in the overlay image can be resampled with vtkImageReslice to match the voxels in the base image. Something like this:

reslice->SetInputData(overlayImage);
reslice->SetInformationInput(baseImage); // reslice like base image
reslice->SetInterpolationModeToLinear();
reslice->Update();
...
blend->SetInputData(0, baseImage);
blend->SetInputData(1, reslice->GetOutput());

Thank you for your suggestion. , I’ve tried with your code,it works well .