[Insight-users] Reading Dicom series

charfeddine amir charfeddine_amir at yahoo.fr
Fri Jan 27 10:38:37 EST 2006


wa alaykom assalam
 plz read the itk software guide.pdf section 7.12.3 Reading a 2D DICOM Series and Writing a Volume
and this is a part of code of file Examples/IO/DicomSeriesReadImageWrite2.cxx :
 
 typedef itk::GDCMImageIO       ImageIOType;
 ImageIOType::Pointer dicomIO = ImageIOType::New();
 reader->SetImageIO( dicomIO );
 
 typedef itk::GDCMSeriesFileNames NamesGeneratorType;
 NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
 nameGenerator->SetUseSeriesDetails( true );
 nameGenerator->SetDirectory( argv[1] );
 
 typedef std::vector< std::string >    SeriesIdContainer;
 const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
 SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();
 SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();
 
 //here we browse all the series in the directory
 
 while( seriesItr != seriesEnd )
   {
   std::cout << seriesItr->c_str() << std::endl;
   seriesItr++;
   }
 
 // and here we choose one serie from the list by its ID given in the command line
 //and if no ID specifies by user, we take the first serie in the list
 
 std::string seriesIdentifier;
 if( argc > 3 ) // If no optional series identifier
   {
   seriesIdentifier = argv[3];
   }
 else
 {
 seriesIdentifier = seriesUID.begin()->c_str();
 }
 
 typedef std::vector< std::string >   FileNamesContainer;
 FileNamesContainer fileNames;
 
 //here we read list of files belonging  to the serie we choose
  
 fileNames = nameGenerator->GetFileNames( seriesIdentifier );
 
 reader->SetFileNames( fileNames );
 
 try
   {
   reader->Update();
   }
 catch (itk::ExceptionObject &ex)
   {
   std::cout << ex << std::endl;
   return EXIT_FAILURE;
   }
 ***********************************************************************************
 //so if u want to deal with every slice alone, u might write something like this
 
 SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();
 SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();
  std::string seriesIdentifier;
  typedef std::vector< std::string >   FileNamesContainer;
 FileNamesContainer fileNames;
 
  //here we browse all the series in the directory
 
 while( seriesItr != seriesEnd )
   {
    seriesIdentifier = seriesItr->c_str();
   fileNames = nameGenerator->GetFileNames( seriesIdentifier );
  reader->SetFileNames( fileNames );
   reader->Update();
    
       {
        // here you write code to process each serie alone
       }
 
    seriesItr++;
   }
 
  
 
For more comments plz read the ITK SOFTWARE GUIDE.PDF from page 298.
 let me know if u resolve your problem, or didn't i understand what u need.
 Amir.
 Technology & Medical Imaging Lab
 Biophysics Departement
 Faculty of Medecine Monastir-Tunisia
 
 
 mahmoud ismail <mahmoudtheleader2003 at yahoo.com> a écrit : salamo alikom
  My problem is that i use vtkDicomReader class and it has a restriction which is
   (the folder that contains the images must have images that belong to the same series and are  ordered) . but in most cases the folder contain images that belongs to more than one series
  so i want to deal with every series alone 
  is it clear
   
  Note my name is mahmoud mohamed Ahmed
  and I am in fourth year systems & and biomedical enginnering department Cairo university Egypt
  what about u

charfeddine amir <charfeddine_amir at yahoo.fr> wrote:
    salam 
sorry i didn't understand your problem
i hope you finded a solution, if not, rewrite me and explain me your problem
because i think i can help u
i make  an application that read dicom series but don't show me all image...
regards,

mahmoud ismail <mahmoudtheleader2003 at yahoo.com> a écrit :    hi Amir
  first i have no answer to your question and hope that the message yuo have recieved 
  is enough but
  I try to open Dicom Images using VTKDicomReader class
  but it cann't distinguish between images that belong to different series
   
  so i used GDCM but i have some problems with it 
  Do u have any suggestions 
  Thanks

charfeddine amir <charfeddine_amir at yahoo.fr> wrote:
      
hi All
I'm developping an application that
 reads the first serie of
Dicom images from a directory, show each image and save it
in bmp format.
the problem is that image series is well readed, and image
  are well saved in bmp format, but image are not well showed
in the vtkrenderwindow used ( i get a black window with
 two
white line on it and not the image readed).
this code in the main file :

this function is for reading first series from a given   
directory and showing it's first dicom image(invoked by 
pushing the Read Directory button in the GUI)
void
migAppBase
::ReadImage()
{
  // Can only read an image once
  if(m_InputImage.IsNotNull())  
   return;
  
  char* chooserName = fl_dir_chooser("select a dicom directory", 0, 0);

  // Store the   filename
  strcpy( m_InputImageDirectoryname, chooserName );
  reader = ReaderType::New();  
  dicomIO =   ImageIOType::New();
  nameGenerator = NamesGeneratorType::New();
 
 reader->SetImageIO( dicomIO );
  nameGenerator->SetUseSeriesDetails( true );
  nameGenerator->SetDirectory( m_InputImageDirectoryname );  
  seriesUID = nameGenerator->GetSeriesUIDs();
    
  seriesIdentifier = seriesUID.begin()->c_str();
     
  fileNames =
 nameGenerator->GetFileNames( seriesIdentifier );

  FileNamesItr = fileNames.begin  ();
  FileNamesEnd = fileNames.end();
    
    
  rescaler = RescaleFilterType::New();
  rescaler->SetOutputMinimum(   0 );
  rescaler->SetOutputMaximum( 255 );
  reader->SetFileName( FileNamesItr->c_str() );  

  try
      {
    rescaler->SetInput( reader->GetOutput() );
    reader->Update();
    m_InputImage = reader->GetOutput();
      m_InputImage->SetRequestedRegionToLargestPossibleRegion();  
    
    // Create the input image VTK pipeline
      this->CreateInputImageWindow();

  }
    catch
 (itk::ExceptionObject &ex)
      {
      }

  FileNamesItr++;
}

this function is for reading the next image in the serie  
(invoked by pushing the Read Next button in the GUI)

 void
migAppBase
::ReadNext()
{


if ( FileNamesItr != FileNamesEnd
 )
{

reader->SetFileName( FileNamesItr->c_str() );

    try
      {
    rescaler->SetInput( reader->GetOutput() );
    m_InputImage = reader->GetOutput();
    m_InputImage->SetRequestedRegionToLargestPossibleRegion();
    reader->Update();
    // Create the input image VTK pipeline  
    this->CreateInputImageWindow();

      }
    catch (itk::ExceptionObject &ex)
      {
      }
FileNamesItr++;
}
}

this   function is for saving the actual image (that should
  be showed in the vtk window) in bmp format (invoked by 
pushing the save   Image in the GUI)


 void
migAppBase
::SaveImage()
{

Writer2Type::Pointer writer2 = Writer2Type::New();

std::string OutputFilename1 = FileNamesItr->c_str() + std::string(".bmp");  
writer2->SetFileName( OutputFilename1.c_str() );
writer2->SetInput( rescaler->GetOutput() );

  try
    {
   
 writer2->Update();
    }
  catch (itk::ExceptionObject & e)
    {
      }

}

this is the fuction for showing the actual image

void
migAppBase
::CreateInputImageWindow()
{
  // If this is the first time we've hit Image Suivante there's other stuff
  // that needs to happen  
  if(m_IsFirstUpdate)
  {
    // Display the output image
    CreateWindowWithRWI(m_InputInteractor, m_InputWindow, "Input Image");

  // these two steps are   VERY IMPORTANT, you have to show() the fltk window  
  // containing the vtkFlRenderWindowInteractor, and then the
  //   vtkFlRenderWindowInteractor
 itself
  m_InputWindow->show();
  m_InputInteractor->show();
   
  // now we get to setup our VTK rendering pipeline  
  CreateInputImageVTKPipeline(m_InputInteractor);

    // No longer the first update
    m_IsFirstUpdate = false;
  }
  else
  {
    // Refresh the output window if not the
 first update
    // NB: doing this on the first update on Windows causes a new  
    // renderwindow to spawn (not sure why)
   m_InputRenderWindow->Render();
  }
  
}

function(s) for fltk and vtk interaction( creation of the
vtkrenderwindow and integrating it to the fltk window)   

void
migAppBase
::CreateWindowWithRWI(vtkFlRenderWindowInteractor *&flrwi, Fl_Window *&flw, char *title)
{
   // set up main FLTK window
   flw = new   Fl_Window(300,330,title);
   
   // and instantiate vtkFlRenderWindowInteractor (here it acts like a  
   // FLTK window, i.e. you   could also
 instantiate it as child of a
   // Fl_Group in a window)
   flrwi = new vtkFlRenderWindowInteractor(5,5,290,260,NULL);

   // this will result in a little message under the rendering  
   Fl_Box* box = new Fl_Box(5,261,290,34,
                             "3 = stereo, j = joystick, t = trackball, "
                           
 "w = wireframe, s = surface, p = pick; "
                            "you can also resize the window");  
   box->labelsize(10);
   box->align(FL_ALIGN_WRAP);
   
   // we're done populating the flw
   flw->end();

   // if the main window gets resized, the vtk window should resize with it
   flw->resizable(flrwi);  
}

void
migAppBase
::CreateInputImageVTKPipeline(vtkFlRenderWindowInteractor *flrwi)
{
  // Abort if the user is   being stupid
  if(m_InputImage.IsNull()) 
    return;

  // create a rendering window and renderer  
  m_InputRenderer =  
 vtkRenderer::New();
  m_InputRenderer->SetBackground(0.0, 0.0, 0.0);
  
  m_InputRenderWindow = vtkRenderWindow::New();
  m_InputRenderWindow->AddRenderer(m_InputRenderer);
     
  // NB: here we treat the vtkFlRenderWindowInteractor just like any other
  // old vtkRenderWindowInteractor
 
 flrwi->SetRenderWindow(m_InputRenderWindow);

  // Hook the VTK pipeline up to the ITK pipeline  
  m_InputImageITKtoVTKexporter = itk::VTKImageExport<InputImageType>::New();
  m_InputImageVTKimporter = vtkImageImport::New();
  m_InputImageITKtoVTKexporter->SetInput( m_InputImage );
  ConnectPipelines(m_InputImageITKtoVTKexporter, m_InputImageVTKimporter);  

  // Need to update prior to creating the cutting planes
  m_InputImageITKtoVTKexporter->Update();
    m_InputImageVTKimporter->Update();

  // Create the image cutting planes
  m_InputImagePlaneX = vtkImagePlaneWidget::New();  
   
 m_InputImagePlaneX->RestrictPlaneToVolumeOn();
  m_InputImagePlaneX->SetResliceInterpolateToCubic();
  m_InputImagePlaneX->SetInput( (vtkDataSet*) m_InputImageVTKimporter->GetOutput() );
  m_InputImagePlaneX->SetPlaneOrientationToXAxes();  
  m_InputImagePlaneX->SetSliceIndex( 0 );
  
  m_InputImagePlaneY =
 vtkImagePlaneWidget::New();
  m_InputImagePlaneY->RestrictPlaneToVolumeOn();
  m_InputImagePlaneY->SetResliceInterpolateToCubic();  
  m_InputImagePlaneY->SetInput( (vtkDataSet*) m_InputImageVTKimporter->GetOutput() );
  m_InputImagePlaneY->SetPlaneOrientationToYAxes();
  m_InputImagePlaneY->SetSliceIndex( 0 );
  // Set the position of the image planes to the center of the volume  
  this->ResetInputImagePlaneWidgets();

  // Link the image planes to   the interactor
  m_InputImagePlaneX->SetInteractor( flrwi );
  m_InputImagePlaneY->SetInteractor( flrwi );

  // Turn on the
 image   plane so they display  
  m_InputImagePlaneX->On();
  m_InputImagePlaneY->On();

  // just like with any other vtkRenderWindowInteractor(), you HAVE to call
  // Initialize() before the interactor will function.  See the docs in  
  // vtkRenderWindowInteractor.h
  // This must occur AFTER the image planes have
 been added to the interactor
  flrwi->Initialize();

  // Clean up memory allocation (NB: not actually deleted until program returns)  
  m_InputRenderer->Delete();
  m_InputRenderWindow->Delete();
}

thx for help
any comment is welcome
Amir


    
---------------------------------
 Nouveau : téléphonez moins cher avec Yahoo! Messenger ! Découvez les tarifs exceptionnels pour appeler la France et l'international. Téléchargez la version beta._______________________________________________
This is  the private VTK discussion list. 
Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers

  

  
  
---------------------------------
  Yahoo! Photos
Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.

    
---------------------------------
 Nouveau : téléphonez moins cher avec Yahoo! Messenger ! Découvez les tarifs exceptionnels pour appeler la France et l'international. Téléchargez la version beta.
  

   

---------------------------------
Do you Yahoo!?
  With a free 1 GB, there's more in store with Yahoo! Mail.


		
---------------------------------
 Nouveau : téléphonez moins cher avec Yahoo! Messenger ! Découvez les tarifs exceptionnels pour appeler la France et l'international.Téléchargez la version beta.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20060127/4a99c653/attachment.htm


More information about the Insight-users mailing list