[vtkusers] Extracting single slices from vtkNIFTIImageReader

Andaharoo Andx_roo at live.com
Mon Sep 10 17:08:59 EDT 2018


If you would like to not use vtkImageViewer2 you can slice the image yourself
with vtkImageReslice to get a 2d image. Then give it to the regular 2d
vtkImageViewer or just write it out.

You just need to set the reslice axes origin and reslice axes direction
cosines. Here's an example of doing it in the XY, YZ, and XZ directions.

// Reslice the image
vtkSmartPointer<vtkImageReslice> reslicer =
vtkSmartPointer<vtkImageReslice>::New();
reslicer->SetInputData(input3dImage);
reslicer->SetInterpolationModeToNearestNeighbor();
reslicer->SetOutputDimensionality(2);
reslicer->SetOutputSpacing(spacing);

// XY
if (direction == SLICE_ORIENTATION_XY)
	reslicer->SetResliceAxesOrigin(0, 0, slice * spacing[2]);
// YZ
else if (direction == SLICE_ORIENTATION_YZ)
{
	reslicer->SetResliceAxesOrigin(slice * spacing[0], 0, (dim[2] - 1) *
spacing[2]);
	reslicer->SetResliceAxesDirectionCosines(
		0, 0, 1,
		0, 1, 0,
		-1, 0, 0);
}
// XZ
else
{
	reslicer->SetResliceAxesOrigin(0, slice * spacing[1], (dim[2] - 1) *
spacing[2]);
	reslicer->SetResliceAxesDirectionCosines(
		0, 0, 1,
		-1, 0, 0,
		0, 1, 0);
}
reslicer->Update();



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list