I want to apply transformations to a given nifti image. How can I apply such as translate, scale, rotation to that? See below example for further reference.
I just applied the vtkImageReslice filter as you can see below and then pass the output nifti image through the DRR algorithm. I have noticed that the output DRR image doesn’t scale-up the ellipsoid (see the attached images) even I passing the transformations as transform->Scale(1.7, 1.8, 1.8).
Did I perform something wrong when applying the vtkImageReslice filter or is this the normal behaviour since the scaling part applies to every voxel in the 3D image ?
vtkSmartPointer<vtkNIFTIImageReader> niftiReader =
vtkSmartPointer<vtkNIFTIImageReader>::New();
niftiReader->SetFileName(ref_volumetric_mesh_voxelized_path.c_str());
niftiReader->Update();
vtkSmartPointer<vtkUnstructuredGridReader> unstructuredGridReader =
vtkSmartPointer<vtkUnstructuredGridReader>::New();
unstructuredGridReader->SetFileName(ref_volumetric_mesh_path.c_str());
unstructuredGridReader->Update();
// Rotate about the center of the image
vtkSmartPointer<vtkTransform> transform =
vtkSmartPointer<vtkTransform>::New();
transform->Scale(1.7, 1.8, 1.8);
vtkSmartPointer<vtkTransformFilter> transformFilterForUSG =
vtkSmartPointer<vtkTransformFilter>::New();
transformFilterForUSG->SetInputConnection(unstructuredGridReader->GetOutputPort());
transformFilterForUSG->SetTransform(transform);
//vtkSmartPointer<vtkPointSet> pd = transformFilter->GetOutput();
vtkSmartPointer<vtkUnstructuredGridWriter> unstructuredGridWriter =
vtkSmartPointer<vtkUnstructuredGridWriter>::New();
unstructuredGridWriter->SetFileName(deformed_volumetric_mesh_path.c_str());
unstructuredGridWriter->SetInputConnection(transformFilterForUSG->GetOutputPort());
unstructuredGridWriter->Write();
// Reslice does all of the work
vtkSmartPointer<vtkImageReslice> reslice =
vtkSmartPointer<vtkImageReslice>::New();
reslice->SetInputConnection(niftiReader->GetOutputPort());
reslice->SetResliceTransform(transform);
reslice->SetInterpolationModeToCubic();
reslice->SetOutputSpacing(
niftiReader->GetOutput()->GetSpacing()[0],
niftiReader->GetOutput()->GetSpacing()[1],
niftiReader->GetOutput()->GetSpacing()[2]);
reslice->SetOutputOrigin(
niftiReader->GetOutput()->GetOrigin()[0],
niftiReader->GetOutput()->GetOrigin()[1],
niftiReader->GetOutput()->GetOrigin()[2]);
reslice->SetOutputExtent(niftiReader->GetOutput()->GetExtent());
reslice->Update();
This is the original nifiti image before applying the transformation.
I have applied vtkImageReslice filter to transform the given nifti image.
I have produced deformed versions, but for some images I was unable to get the whole ellipsoid and only appear some part of the ellipsoid (see attached sample images)?
I’m writing this to ask about the SetResliceAxes functionality. Should I use this here in order to overcome this issue? if so how ?
// Reslice does all of the work
vtkSmartPointer reslice =
vtkSmartPointer::New();
reslice->SetInputConnection(niftiReader->GetOutputPort());
reslice->SetResliceTransform(transform);
reslice->SetInterpolationModeToCubic();
reslice->SetOutputSpacing(
niftiReader->GetOutput()->GetSpacing()[0],
niftiReader->GetOutput()->GetSpacing()[1],
niftiReader->GetOutput()->GetSpacing()[2]);
reslice->SetOutputOrigin(
niftiReader->GetOutput()->GetOrigin()[0],
niftiReader->GetOutput()->GetOrigin()[1],
niftiReader->GetOutput()->GetOrigin()[2]);
reslice->SetOutputExtent(niftiReader->GetOutput()->GetExtent());
reslice->Update();