Reputation: 1
I tried the following code, but the output is absolutely wrong.
warp = sitk.WarpImageFilter()
warp.SetInterpolator(sitk.sitkLinear)
out = warp.Execute(reference_img, transform_img)
it gives me exactly the reference_img, but not the transformed image.
Have you ever used this function? Could you please help me on this issue?
Upvotes: 0
Views: 1545
Reputation: 1431
The WarpImageFilter, as with all of the other SimpleITK filters, is rigorously tested in the SimpleITK build infrastructure. The filter wrapping include descriptions of multiple test where the results are validated and the behavior across languages is verified. Additionally in SimpleITK, all filters are automatically tested for consistency on several behaviors which is accomplished though the code generation process SimpleITK has.
The ResampleImageFilter
is now the preferred method over the WarpImageFilter. It applies any transform to resample an image, where a DisplacementFieldTransform
contains the displacement field image. This is different than the WarpImageFilter
which just takes the displacement field.
There seems to be some confusion for the "reference image". Both the resample and the warp filter need to know the output information for the image. This includes the output origin, output size, output spacing and output direction. These can manually be set individually or from a "reference image". There is the ResampleImageFilter.SetRefenceImage()
and the WarpImageFilter.SetOutputParametersFromImage
methods which do the same thing. the reference image is optional.
Sample usage of the WarpImageFilter
utilizing the SimpleITK test data:
img = sitk.ReadImage("cthead1-Float.mha")
dis = sitk.ReadImage("cthead1-dis1.nrrd")
warper = sitk.WarpImageFilter()
warper.SetOutputParameteresFromImage(img)
out = warper.Execute(img,dis)
Here is the same operation done with the ResampleImageFilter. It requires converting the displacement field image to float64 to be used with the transform:
resampler = sitk.ResampleImageFilter()
resampler.SetReferenceImage(img)
dis_tx = sitk.DisplacementFieldTransform(sitk.Cast(dis,sitk.sitkVectorFloat64))
resampler.SetTransform(dis_tx)
out = resampler.Execute(img)
Upvotes: 2