[Insight-users] Image Series Reader/Writer with ConnectedThresholdImageFilter

joisan hiki.3joi at gmail.com
Fri Nov 16 08:28:02 EST 2012


I am a new user for ITK. I wish to segment bone from CT scan images. I have
tried to use image series reader to read png images and filter them with
connected threshold image filter. But, the output using image series writer
only produced black images. I am sure that there is no problem with the
reader and writer as I have tested it. As for the seed point, I am sure it
is correct as I have also tested it with single image. Hence, I am wondering
whether this function is only working for single image instead of volume
images.

Below is my code:

  typedef   float           InternalPixelType;
  const     unsigned int    Dimension = 3;
  typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
  typedef itk::ImageSeriesReader< InternalImageType >        ReaderType;
  ReaderType::Pointer reader = ReaderType::New();

  typedef itk::NumericSeriesFileNames NamesGeneratorType;
  NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();

  nameGenerator->SetSeriesFormat( "XXXXX\\IM%03d.PNG" );

  nameGenerator->SetStartIndex( 000 );
  nameGenerator->SetEndIndex( 002 );
  nameGenerator->SetIncrementIndex( 1 );

  reader->SetImageIO( itk::PNGImageIO::New() );

  reader->SetFileNames( nameGenerator->GetFileNames()  );

    try
      {
      reader->Update();
      }
    catch (itk::ExceptionObject &ex)
      {
      std::cout << ex << std::endl;
	  //std::system("pause");
      return EXIT_FAILURE;
      }

  typedef unsigned char                    OutputPixelType;
  typedef itk::Image< OutputPixelType, 3 > ThresholdImageType;
  typedef itk::Image< OutputPixelType, 2 > OutputImageType;

  typedef itk::ConnectedThresholdImageFilter< InternalImageType,
                                    ThresholdImageType >
ConnectedFilterType;

  ConnectedFilterType::Pointer connectedThreshold =
ConnectedFilterType::New();
 
  connectedThreshold->SetInput( reader->GetOutput() );

  const InternalPixelType lowerThreshold = atof( "250" );
  const InternalPixelType upperThreshold = atof( "255" );

  connectedThreshold->SetLower(  lowerThreshold  );
  connectedThreshold->SetUpper(  upperThreshold  );
 
  connectedThreshold->SetReplaceValue( 255 );

  InternalImageType::IndexType  index;

  index[0] = atoi( "273" );
  index[1] = atoi( "349" );

  connectedThreshold->SetSeed( index );

  itk::NumericSeriesFileNames::Pointer fit =
itk::NumericSeriesFileNames::New();

  typedef  itk::ImageSeriesWriter<ThresholdImageType,OutputImageType>
WriterType; 

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


  std::string format = "XXXX\\IM";
  format += "%03d.";
  format += "PNG"; // filename extension

  InternalImageType::RegionType region =
reader->GetOutput()->GetBufferedRegion();
  InternalImageType::SizeType   size = region.GetSize();

  fit->SetStartIndex(0);
  fit->SetEndIndex(size[2]-1);  // The number of slices to write
  fit->SetIncrementIndex(1);
  fit->SetSeriesFormat (format.c_str());

  writer->SetInput(connectedThreshold->GetOutput());
  writer->SetFileNames(  fit->GetFileNames() );

 
  if( writer->GetUseCompression() )
    {
    std::cerr << "Wrong default use compression value" << std::endl;
    return EXIT_FAILURE;
    }
  writer->SetUseCompression( true );
  writer->UseCompressionOn();
  writer->UseCompressionOff();

  try
    {
    writer->Update();
    }
  catch( itk::ExceptionObject & excep )
    {
    std::cerr << "Exception caught !" << std::endl;
    std::cerr << excep << std::endl;
    }

Please forgive for any inconvenience and thanks.
 



--
View this message in context: http://itk-insight-users.2283740.n2.nabble.com/Image-Series-Reader-Writer-with-ConnectedThresholdImageFilter-tp7581669.html
Sent from the ITK Insight Users mailing list archive at Nabble.com.


More information about the Insight-users mailing list