[vtkusers] rescaling an image with vtkimageReslice
skific_riteh
skific at riteh.hr
Tue Jul 3 03:37:33 EDT 2012
thx for the reply, but...
In addition to your comments, I had to set
resize->SetOutputDimensions(1024,1024,0);
in order for get the scaled image.
Neverthless, I can't seem to understand why the vtkImageReslice and
vtkImageResample show three pixels less in each direction. I had set
BorderOn() on reslice and resample objs, but with no effect. I did call
Update() fn after I had set all parameters on reslice and resample objs.
Any thoughts?
btw, I'm trying to implement a different interpolator in vtk (by
subclassing the vtkAbstractImageInterpolator), so I'm quite interested
in the behaviour of those classes.
and yeah, I do use vtk 5.10
thx
On 2.7.2012. 15:28, David Gobbi wrote:
> 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