[Insight-users] a question about using itkImageToVTKImageFilter

Karthik Krishnan Karthik.Krishnan at kitware.com
Mon Aug 29 12:21:37 EDT 2005



LI XIN wrote:

>Hello,
>
>Thank you very much for your reply!
>
>I added the line conncetor->Update(); The VTK image data spacing is right now. But the dimensions are still wrong.
>
The dimensions should also propagate throught the call back just like 
the spacing does

> They are 0,255, 0. 
>
can you add the line
  connector->GetOutput()->Print( std::cout );

after connector->Update();
and post the print log of vtkImageData.

-karthik

>The slice image cannot be displayed properly yet. 
>
>Please tell me what the problem is. 
>
>Thanks a lot!
>
>Xin
>
>
>----- Original Message -----
>From: Karthik Krishnan <Karthik.Krishnan at kitware.com>
>Date: Friday, August 26, 2005 6:38 pm
>Subject: Re: [Insight-users] a question about using itkImageToVTKImageFilter
>
>  
>
>>LI XIN wrote:
>>
>>    
>>
>>>Hello, insight users
>>>
>>>I have a question when I use itkImageToVTKImageFilter.
>>> 
>>>
>>>      
>>>
>>This class propagates its metadata (spacing info) etc via 
>>callbacks 
>>which *will not* be triggered unless you make an Update() call... 
>>You 
>>were just missing the line
>>
>>connector->Update();
>>
>>[The image itself is available since it is passed around as a raw 
>>pointer.]
>>HTH
>>karthik
>>
>>    
>>
>>>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
>>>
>>>_______________________________________________
>>>Insight-users mailing list
>>>Insight-users at itk.org
>>>http://www.itk.org/mailman/listinfo/insight-users
>>>
>>> 
>>>
>>>      
>>>
>
>  
>


More information about the Insight-users mailing list