[vtkusers] vtkImageData resampling

David Gobbi david.gobbi at gmail.com
Wed Jan 15 08:02:12 EST 2014


Hi Tony,

Can you provide details about your system, such as what version of VTK
you are using, what operating system, and what compiler?  Also, if you
are able to run the code in a debugger, it would be very useful if you
could use the debugger to find the line number where the crash occurs.

The output spacing for vtkImageResample does not have to be a multiple
of the input spacing. The only thing that is unusual about your code
is the presence of vtkImageChangeInformation, because the output of
the resampler should already be (spx,spy,spz).  Are there times when
the output of vtkImageResample is different from the spacing that you
selected?

An alternative to vtkImageResample is vtkImageReslice, which can be
used as follows:

vtkSmartPointer<vtkImageReslice> resample =
  vtkSmartPointer<vtkImageReslice>::New();
resample->SetInput(imgData);
resample->SetInterpolationModeToLinear();
resample->SetOutputSpacing(spx,spy,spz);

  David


On Wed, Jan 15, 2014 at 2:38 AM, Tony <bowler0_uk at yahoo.com> wrote:
> Dear list,
>
> I am having problems with vtkImageResample I frequently want to resample images and I currently use a procedure along the lines of
>     vtkSmartPointer<vtkImageResample>resampler=
> vtkSmartPointer<vtkImageResample>::New();
> resampler->SetInput(imgData);
> resampler->SetDimensionality(3);
> resampler->SetAxisOutputSpacing(0,spx);
> resampler->SetAxisOutputSpacing(1,spy);
> resampler->SetAxisOutputSpacing(2,spz);
>     resampler->Update();
> vtkSmartPointer<vtkImageChangeInformation>v16=
> vtkSmartPointer<vtkImageChangeInformation>::New();
> v16->SetInputConnection(resampler->GetOutputPort());
> v16->SetOutputSpacing(spx,spy,spz);
> v16->Update();
>
> which I imagine I got from an example some time ago. I have found this method to be rather unstable in
> that certain values of grid spacing will cause a runtime error. The values of spx, spy and spz that cause
> a crash are rather unpredictable in that I can't see a patttern between the characteristics of the input
> data and values that result in a crash. It is often quite chaotic for example SetSpacing(2, 2, 2) and
> SetSpacing(2.2, 2.2, 2.2) might cause a crash whilst SetSpacing(2.1, 2.1, 2.1) will be fine.
>
> Is there any obvious gremlin in the above code? If not is there a more general way about going about this?
> Perhaps I've been rather lazy in that I haven't taken the time to explore how vtkImageResample works in
> detail, I don't know if the new spacing has to be an exact multiple of the old one or vice versa.


More information about the vtkusers mailing list