[vtkusers] rescaling an image with vtkimageReslice

David Gobbi david.gobbi at gmail.com
Mon Jul 2 09:28:00 EDT 2012


If you are using VTK 5.10, you can try using the new filter
vtkImageResize.  It has an option called BorderOn() that will provide
the behavior that you are looking for:

resize->SetResizeMethodToMagnificationFactors();
resize->SetMagnificationFactors(4,4,1);
resize->BorderOn();
resize->InterpolationOn();

Documentation for the BorderOn() method:

  "If Border is Off (the default), then the centers of each of the
  corner voxels will be considered to form the rectangular bounds
  of the image. This is the way that VTK normally computes image
  bounds. If Border is On, then the image bounds will be defined by
  the outer corners of the voxels. This setting impacts how the
  resizing is done.  For example, if a MagnificationFactor of two is
  applied to a 256x256 image, the output image will be 512x512 if
  Border is On, or 511x511 if Border is Off."

 - David

On Mon, Jul 2, 2012 at 12:11 AM, skific_riteh <skific at riteh.hr> wrote:
> I had tried to rescale an image with vtkImageReslice, and somehow lost three
> pixels in each direction.
> As I understood, the resulting image should be 256*4 and 256*4 in size.
> However, the image is 256*4-3 in size in every direction. What am I doing
> wrong?
> btw, when I apply the vtkImageResample with SetAxisMagnificationFactor fns
> in directions 0 and 1 with factor 4,
> I get the same result as with the vtkImageReslice.
> Now the code looks like this:
> ...
> std::string path = "$VTK_DATA_ROOT/Data/masonry.bmp";
>     vtkSmartPointer<vtkImageReader2Factory> readerFactory =
>         vtkSmartPointer<vtkImageReader2Factory>::New();
>     vtkSmartPointer<vtkImageReader2> imageReader =
> readerFactory->CreateImageReader2(path.c_str());
>     imageReader->SetFileName(path.c_str());
>     imageReader->SetDataExtent(0, 255, 0, 255, 0, 0);
>     imageReader->SetDataSpacing(1, 1, 1);
>     imageReader->SetDataOrigin(0, 0, 0);
>     imageReader->UpdateWholeExtent();
> vtkSmartPointer<vtkImageReslice> reslice1  =
> vtkSmartPointer<vtkImageReslice>::New();
> reslice1->SetInputConnection(imageReader->GetOutput()->GetProducerPort());
>     reslice1->SetOutputSpacing(0.25,0.25,1);
>     reslice1->Update();
> vtkSmartPointer<vtkBMPWriter> writer = vtkSmartPointer<vtkBMPWriter>::New();
>     writer->SetFileName("output_reslice.bmp");
>     writer->SetInput(reslice1->GetOutput());
>     writer->Write();
> ...
> thanx



More information about the vtkusers mailing list