[Insight-users] Warping an Image?

Luis Ibanez luis.ibanez@kitware.com
Tue, 25 Feb 2003 07:24:38 -0500


Hi Chad,

Please take a look at the description of the
ResampleImageFilter in the SoftawareGuide

  http://www.itk.org/ItkSoftwareGuide.pdf

You will find it in Section 5.7, pdf-pages 137
to 153. This filter use the sampe principle
than the wrap image filter.

When you deform an image with the wrap image
filter, the deformation field is applied
in the reverse direction of what you may
expect.  The reason is quite simple: The only
way to obtain a 'dense' output image is to
perform the transformation by

1) creating first the grid of the output image
2) visiting each pixel of the output grid
3) for each pixel do:
3.1)  get its spatial coordinates given the
       output grid origin and spacing
3.2)  Using the deformation field, map the
       spatial coordinates into the input
       image space. (Here is what may seem
       counter intuitive).
3.3)  with the coordinates in the input image
       find the associated grid point of the
       input image and get its intensity value.
       (the input image, origin and spacing
        are considered at this stage).
3.4)  if the point mapped in a non-grid position
       use an interpolator in order to compute
       the intensity from neighbor pixels.
3.5)  put the intensity in the corresponding
       pixel of the output image.


When you finish visiting all the pixels of the
output image... you are done.

----

You can look directly at the code in the
ThreadedGenerateData() method defined in the
.txx file. This is the core of the filter

---

The approach of using the wrap field as a forward
transformation does not allow to generate a dense
image at the output. The image will necessariry
result with holes because by visiting the grid of
the input image, not all the pixels of the output
grid will receive correspondances.

Reading the section on the resample image filter
will make this clearer.

----

Now that, in this filter it could be quite easy
to add an options "ReverseOn()" in which by setting
a boolean we could change the sign of every vector
in the deformation field. This is an easy change
in the code. (Note that technically this is not
the inverse of the transformation unless all
the vectors are infinitesimal...).

Would you find this option useful ?


Please let us know if you have further questions,


Thanks


    Luis


------------------------------------

Chad Washington wrote:
> I am attempting to use the itkWarpImageFilter on a 2-D image.  My deformation 
> field is an image of 2-D vectors defining x and y displacements.  They both 
> have the same size, origin and spacing.  My deformation field is calculated 
> from a finite element mesh.  I have viewed the deformation field plotted 
> against my mesh, and believe that it is correct.  However, my deformed image 
> looks nothing like what I predict.  It actually looks as if the field is 
> being applied in the opposite direction, i.e. my deformed image appears 
> stretched rather than compressed.  I have tried the 
> BSplineInterpolateImageFunction.  With this the image is smoother, but it is 
> still not being deformed correctly.  I also tried reversing my field.  
> Currently, the field is defined for each pixel position of the original input 
> image.  Is this wrong? Should it define the inverse mapping for the pixels of 
> the output image?  I have been working with the assumption that the 
> WarpImageFilter does the inverse mapping for you.  I would be extremely 
> thankful to anyone that has used this filter and can provide some tips on its 
> use.
> 
> Chad Washington
> Biomedical Modeling Lab
> Dept. of Biomedical Engineering
> Vanderbilt University
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
>