[Insight-users] a question about using itkImageToVTKImageFilter
LI XIN
xli16 at jhem.jhmi.edu
Fri Aug 26 16:54:36 EDT 2005
Hello, insight users
I have a question when I use itkImageToVTKImageFilter.
I tried to use itkImageFileReader to read a 3D raw image file, change it to VTK image data using itkImageToVTKImageFilter, and then display one slice of the image using vtkImageViewer. But the slice could not be displayed properly.
I found that the data spacing are 1 ,1 ,1 and the dimensions are 0 , -1 , 0 after ITK image data changed to VTK image data.
My code is:
typedef float PixelType;
const unsigned int Dimension = 3;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::ImageFileReader< ImageType > ReaderType;
typedef itk::RawImageIO<PixelType, Dimension> ImageIOType;
typedef itk::ImageToVTKImageFilter< ImageType > ConnectorType;
ReaderType::Pointer reader = ReaderType::New();
ImageIOType::Pointer rawIO = ImageIOType::New();
ConnectorType::Pointer connector = ConnectorType::New();
reader->SetImageIO(rawIO);
reader->SetFileName( "brain.raw" );
rawIO->SetFileDimensionality(3);
rawIO->SetOrigin(0,0.0);
rawIO->SetOrigin(1,0.0);
rawIO->SetOrigin(2,0.0);
rawIO->SetDimensions(0,256);
rawIO->SetDimensions(1,256);
rawIO->SetDimensions(2,50);
rawIO->SetSpacing(0,0.9609375);
rawIO->SetSpacing(1,0.9609375);
rawIO->SetSpacing(2,2.2);
try
{
reader->Update();
}
catch (itk::ExceptionObject & err)
{
cout << "ExceptionObject caught!" << endl;
cout << err << endl;
return -1;
}
connector->SetInput(reader->GetOutput());
vtkImageViewer *viewer=vtkImageViewer::New();
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
viewer->SetInput(connector->GetOutput());
float max=(((vtkDataSet *)(connector->GetOutput()))->GetScalarRange())[1];
viewer->SetZSlice(10);
viewer->SetColorWindow(max);
viewer->SetColorLevel(max/2.0);
viewer->SetupInteractor(iren);
viewer->Render();
iren->Initialize();
iren->Start();
I tried a .png image file and it worked very well. I couldn't find out the reason why the parameters of VTK image data changed. How should I do?
Thank you very much!
xin
More information about the Insight-users
mailing list