[Insight-users] How to use multithreaded-filters

Mª Dolores Villalobos Ortiz lolalobos17 at yahoo.es
Sun Mar 13 09:36:44 EDT 2011


Hi

I'm starting to use ITK toolkit and I'm interested in working using several threads. Until now, I have been doing tests using "itkFlipImageFilter" (according to ITK documentation, it's a multhreaded filter). The main program runs fine, but I think only one thread is spawned because I switch on/off one core and execution times are similar (I'm working on Linux and processor has 2 cores). I compile the next code (this example is provided
 by ITK toolkit):

int main( int argc, char * argv[] )
{
  typedef   unsigned char  PixelType;

  itk::MultiThreader::SetGlobalDefaultNumberOfThreads(2); 

  typedef itk::Image< PixelType,  2 >   ImageType;

  typedef
 itk::ImageFileReader< ImageType >  ReaderType;
  typedef itk::ImageFileWriter< ImageType >  WriterType;

  ReaderType::Pointer reader = ReaderType::New();
  WriterType::Pointer writer = WriterType::New();

  reader->SetFileName("example.jpg");
  writer->SetFileName("example2.jpg");

  typedef itk::FlipImageFilter< ImageType >  FilterType;

  FilterType::Pointer filter = FilterType::New();

  typedef FilterType::FlipAxesArrayType     FlipAxesArrayType;
  
  FlipAxesArrayType flipArray;

  flipArray[0] = 1;
  flipArray[1] = 0;

  filter->SetFlipAxes( flipArray );
  
  filter->SetInput( reader->GetOutput() );
  writer->SetInput( filter->GetOutput() );
  writer->Update();
 
  return
 EXIT_SUCCESS;
}


 ITK toolkit and my example are compiled in Debug mode.

Thank you

P.S. Sorry, my English is not very good.



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110313/981e1eb6/attachment.htm>


More information about the Insight-users mailing list