Deform a CT image volume using the vtkImageReslice

I want to apply transformations such as translate, scale, rotation to a given 3D CT image volume (mhd format). For that I have used vtkImageReslice function as below. But the output seems not correctly deformed as expected.

Should I need to set resliceAxes in order to correctly deformed the image volume ? If so how ? or any mistake that I have done here ?

The image header information and the code snippet is given below for your further reference.

ObjectType = Image
NDims = 3
BinaryData = True
BinaryDataByteOrderMSB = False
CompressedData = False
TransformMatrix = 1 0 0 0 -1 0 0 0 1
Offset = -196.615234375 196.615234375 -250
CenterOfRotation = 0 0 0
AnatomicalOrientation = RPI
ElementSpacing = 0.76953125 0.76953125 1
DimSize = 512 512 501
ElementType = MET_FLOAT
ElementDataFile = volume-10.raw

The code is below.

vtkSmartPointer<vtkMetaImageReader> imageReader =
        vtkSmartPointer<vtkMetaImageReader>::New();
    imageReader->SetFileName(ref_imagevolume_path.c_str());
    imageReader->Update();

vtkSmartPointer<vtkTransform> transform1 =
        vtkSmartPointer<vtkTransform> ::New();
    transform1->Scale(1.2, 1.2, 1.2);

vtkSmartPointer< vtkImageReslice > reslice =
            vtkSmartPointer<vtkImageReslice >::New();
        reslice->SetInputConnection(imageReader->GetOutputPort());
        reslice->SetResliceTransform(transform1->GetInverse());
        //reslice->SetInterpolationModeToCubic();
        reslice->SetOutputDimensionality(3);
        reslice->SetInterpolationModeToNearestNeighbor();

reslice->SetOutputSpacing(
            imageReader->GetOutput()->GetSpacing()[0],
            imageReader->GetOutput()->GetSpacing()[1],
            imageReader->GetOutput()->GetSpacing()[2]);

        reslice->SetOutputOrigin(
            imageReader->GetOutput()->GetOrigin()[0],
            imageReader->GetOutput()->GetOrigin()[1],
            imageReader->GetOutput()->GetOrigin()[2]);
        reslice->SetOutputExtent(imageReader->GetOutput()->GetExtent());

        reslice->Update();

vtkSmartPointer<vtkMetaImageWriter> writer = vtkSmartPointer<vtkMetaImageWriter>::New();
        writer->SetFileName(deformed_image_volume.c_str());
        writer->SetInputData(reslice->GetOutput());
        writer->Write();

A vague suggestion: Could it be that you need to set the correct spacing for the output data of the reslice object according to the applied scaling in transform?

Should I change my code as below. Or any other way ? Can you please elaborate with a simple example code if possible.

reslice->SetOutputSpacing(
imageReader->GetOutput()->GetSpacing()[0] * 1.2,
imageReader->GetOutput()->GetSpacing()[1] * 1.2,
imageReader->GetOutput()->GetSpacing()[2] * 1.2);

Yes, that is what I meant actually. I am not very fond with scaling volumes and images with VTK, but I can imagine that if you do so, the output parameters for the reslice object needs to fit the performed operations results.

Additionally, if this does not deliver the results you expect, maybe a translation regarding the center of the volume before scaling it is needed, like so:

transform1->Translate(
imageReader->GetOutput()->GetCenter[0],
imageReader->GetOutput()->GetCenter[1],
imageReader->GetOutput()->GetCenter[2]);
transform1->Scale(1.2, 1.2, 1.2);
transform1->Translate(
-(imageReader->GetOutput()->GetCenter[0]),
-(imageReader->GetOutput()->GetCenter[1]),
-(imageReader->GetOutput()->GetCenter[2]));

This makes sure the volume is centered before the scaling is done.
Can you give it a try?

Also, not sure why you use

instead of simply

reslice->SetRescliceTransform(transform1);

?

The actual tranform is not include only the scaling factor but also rotation and translation as well for example as below.

  vtkSmartPointer<vtkTransform> transform1 =
        vtkSmartPointer<vtkTransform> ::New();
    transform1->Translate(0.3, 0.7, 0.1);
    transform1->Scale(1.1, 0.8, 1.2);
    transform1->RotateX(5);

I have changed the reslice spacing and the origin by mutiply it with the scaling factor as below. Now I think the issue is gone. I assume I do not need to worry about translation and the rotation factors right ?

       reslice->SetOutputSpacing(
            imageReader->GetOutput()->GetSpacing()[0] * transform->GetScale()[0],
            imageReader->GetOutput()->GetSpacing()[1] * transform->GetScale()[1],
            imageReader->GetOutput()->GetSpacing()[2] * transform->GetScale()[2]);

      	reslice->SetOutputOrigin(
            imageReader->GetOutput()->GetOrigin()[0] * transform->GetScale()[0],
            imageReader->GetOutput()->GetOrigin()[1] * transform->GetScale()[1],
            imageReader->GetOutput()->GetOrigin()[2] * transform->GetScale()[2]);
        reslice->SetOutputExtent(imageReader->GetOutput()->GetExtent());