Inputs physical space do not match when using itk.LabelMapOverlayImageFilter

Hi,
I have a DICOM Series which I loaded as well as a series of PNG files which are the segmentations. I am trying to overlay, the segmentations on top of the DICOM series, however I get this error when I do:

itk.GetArrayFromImage(labelMapOverlayImageFilter.GetOutput())
itk::ERROR: LabelMapOverlayImageFilter(0x7ff266c0e790): Inputs do not occupy the same physical space! 
InputImage Origin: [-1.1700000e+02, -1.1972100e+02, -4.5426899e+01], InputImage_1 Origin: [-1.1700000e+02, -1.1972200e+02, -4.5426701e+01]
	Tolerance: 4.6875000e-07
InputImage Spacing: [4.6875000e-01, 4.6874800e-01, 6.0001812e+00], InputImage_1 Spacing: [4.6875000e-01, 4.6874800e-01, 6.0002131e+00]
	Tolerance: 4.6875000e-07

As you can see the difference is very minute:

origin:
in1: [-1.1700000e+02, -1.1972100e+02, -4.5426899e+01]
in2: [-1.1700000e+02, -1.1972200e+02, -4.5426701e+01]

spacing:
in1: [4.6875000e-01, 4.6874800e-01, 6.0001812e+00]
in2: [4.6875000e-01, 4.6874800e-01, 6.0002131e+00]

Is there any recommended best practice to deal with this?

Thanks

Hi nvm I think I solved my own problem :smiley:
For anyone having the same problems you need to resample the labels to the reference image here is my solution

resampleImageFilter = itk.ResampleImageFilter[IUC3, IUC3].New()
resampleImageFilter.SetInput(niiFileReader.GetOutput())
resampleImageFilter.SetTransform(itk.IdentityTransform[itk.D, 3].New())
resampleImageFilter.SetInterpolator(itk.NearestNeighborInterpolateImageFunction[IUC3, itk.D].New())
resampleImageFilter.UseReferenceImageOn()
resampleImageFilter.SetReferenceImage(imageSeriesReader.GetOutput())
1 Like

You could invoke filter->SetCoordinateTolerance() or change GlobalDefaultCoordinateTolerance. You should take a look at ImageToImageFilter documentation (scroll down to description, there is a long list of derived classes at the beginning of that page).