[Insight-users] a question about using itkImageToVTKImageFilter

Karthik Krishnan Karthik.Krishnan at kitware.com
Tue Aug 30 17:25:01 EDT 2005


Hi Li,

Given that your vtkImageData looks good, you are probably using poor 
window level settings. What do you mean by :"

the slice cannot be displayed properly yet. " ? 

The default vtkImageViewer should usually be able to display it just fine with appropriately chosen WL settings as in

                     
  itktovtkconnector->SetInput(reader->GetOutput());
  vtkImageViewer *viewer=vtkImageViewer::New();
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  viewer->SetInput(connector->GetOutput());
  viewer->SetZSlice(10);
  viewer->SetupInteractor(iren);
  viewer->Render();
  iren->Initialize();
  iren->Start();


HTH
karthik


LI XIN wrote:

>Hello,  Karthik Krishnan
>
>Here is the print log:
>
>vtkImageData (00349CC0)
>  Debug: Off
>  Modified Time: 88
>  Reference Count: 1
>  Registered Events: (none)
>  Source: 00349BB0
>  Release Data: Off
>  Data Released: False
>  Global Release Data: Off
>  MaximumNumberOfPieces: -1
>  PipelineMTime: 81
>  UpdateTime: 89
>  UpdateExtent: Not Initialized
>  Update Number Of Pieces: 1
>  Update Piece: 0
>  Update Ghost Level: 0
>  RequestExactExtent: Off
>   UpdateExtent: 0, 255, 0, 255, 0, 49
>  WholeExtent: 0, 255, 0, 255, 0, 49
>  Field Data:
>    Debug: Off
>    Modified Time: 76
>    Reference Count: 1
>    Registered Events: (none)
>    Number Of Arrays: 0
>    Number Of Components: 0
>    Number Of Tuples: 0
>  Locality: 0
>  NumberOfConsumers: 0
>  ExtentTranslator: (00349E90)
>  MaximumNumberOfPieces: -1
>  Number Of Points: 3276800
>  Number Of Cells: 3186225
>  Cell Data:
>    Debug: Off
>    Modified Time: 78
>    Reference Count: 1
>    Registered Events: (none)
>    Number Of Arrays: 0
>    Number Of Components: 0
>    Number Of Tuples: 0
>    Copy Flags: ( 1 1 1 1 1 )
>    Scalars: (none)
>    Vectors: (none)
>    Normals: (none)
>    TCoords: (none)
>    Tensors: (none)
>  Point Data:
>    Debug: Off
>    Modified Time: 87
>    Reference Count: 1
>    Registered Events: (none)
>    Number Of Arrays: 1
>    Array 0 name = NULL
>    Number Of Components: 1
>    Number Of Tuples: 3276800
>    Copy Flags: ( 1 1 1 1 1 )
>    Scalars:
>      Debug: Off
>      Modified Time: 84
>      Reference Count: 1
>      Registered Events: (none)
>      Name: (none)
>      Number Of Components: 1
>      Number Of Tuples: 3276800
>      Size: 3276800
>      MaxId: 3276799
>      LookupTable: (none)
>      Array: 01AB0040
>    Vectors: (none)
>    Normals: (none)
>    TCoords: (none)
>    Tensors: (none)
>  Bounds:
>    Xmin,Xmax: (0, 245.039)
>    Ymin,Ymax: (0, 245.039)
>    Zmin,Zmax: (0, 107.8)
>  Compute Time: 0
>  Release Data: Off
>  ScalarType: 10
>  NumberOfScalarComponents: 1
>  Spacing: (0.960938, 0.960938, 2.2)
>  Origin: (0, 0, 0)
>  Dimensions: (256, 256, 50)
>  Increments: (1, 256, 65536)
>  Extent: (0, 255, 0, 255, 0, 49)
>  WholeExtent: (0, 255, 0, 255, 0, 49)
>
>I found I made a mistake. The dimensions of the VTK image data are right. But the slice cannot be displayed properly yet. 
>The following is my code to display the slice. Please take a look at it. Is there something wrong in it so that I cannot display the slice properly?
>  
>

>                     vtkLookupTable *lut = vtkLookupTable::New();
>	lut->SetHueRange(0.0,0.0);
>	lut->SetSaturationRange(0.0,0.0);
>	lut->SetValueRange(0.0,1.0);
>
>	vtkExtractVOI *extract = vtkExtractVOI::New();
>	extract->SetInput(connector->GetOutput());
>
>	extract->SetVOI(0,255,0,255,30,30);
>
>	vtkDataSetMapper *imageMapper = vtkDataSetMapper::New();
>	imageMapper->SetInput((vtkDataSet *)extract->GetOutput());
>	imageMapper->SetLookupTable(lut);
>
>	vtkActor *imageActor = vtkActor::New();
>	imageActor->SetMapper(imageMapper);
>
>	vtkRenderer *imageRen = vtkRenderer::New();
>	imageRen->AddActor(imageActor);
>	imageRen->SetBackground(1,1,1);
>
>	vtkRenderWindow *renWin = vtkRenderWindow::New();
>                     renWin->AddRenderer(imageRen);
>	renWin->SetSize(640,480);
>
>	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
>                     iren->SetRenderWindow(renWin);
>
>	iren->Initialize();
>	iren->Start(); 
>
>Could you please give me your help? Thanks a lot!
>
>Xin
>
>
>
>
>----- Original Message -----
>From: Karthik Krishnan <Karthik.Krishnan at kitware.com>
>Date: Monday, August 29, 2005 12:21 pm
>Subject: Re: [Insight-users] a question about using itkImageToVTKImageFilter
>
>  
>
>>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