[vtkusers] odd vtkImageData interpolation behavior
David Feng
dfeng at cs.unc.edu
Wed Jun 18 16:28:45 EDT 2008
I noticed some odd behavior when interpolating a vtkImageData object.
Rather than make a 2D image and rotate it to the XZ plane, I made it a
3D image with dimensions (x,1,y). When I call FindCell simply using the
world-space pixel coordinates, the interpolated values were not what I
expected. Taking a closer look at the function, I noticed the following:
return loc[2] * (dims[0]-1)*(dims[1]-1) +
loc[1] * (dims[0]-1) + loc[0];
...where loc is the interpolated image-space pixel coordinate and dims
are the dimensions of the image. The return value is supposed to the 1D
array index within the image. With this formula, a pixel location of
(0,0,5) and (0,0,0) have the same 1D index for an image such as mine (XZ
instead of XY, with dimensions (x,1,y)). I haven't looked more
closely, but indexing into a 3D should actually look like this, if I'm
not mistaken:
return loc[2] * dims[0] * dims[1] +
loc[1] * dims[0] + loc[0];
I'm not sure why the dimensions are being decremented in the original
code. It would seem to make the indexing off by several pixels for each
row and slice. When I made the change, I started getting the values I
expected. A simple way to test this is to use a vtkProbeFilter to probe
an XZ image using itself as the input sample points -- without the
change, my input is different from my output, which should not be the
case. Am I missing something?
Thanks,
David
More information about the vtkusers
mailing list