[Insight-users] CannyLevelSet Speed Image - dimension returned Zero

conn sullivan sullivanconn at yahoo.com
Fri Mar 25 16:06:08 EST 2005


Hello All,
 
I am new to ITK and currently trying to check with Level set segmentation methods. 
I have written following code to refine the segmentation of Threshold Level Set.  I have used different types of images for this as input.  The problem is:  speed image returned is of 0 bytes, basically GetRegionIO() receives 0 as dimension of the input image. 
Does anyone have idea why this is happening? 
 
Ex. --> 
Input Files used -->
Input FileName   --> c:\\BrainT1Slice_thresholdLevelSet.png
Feature Image    --> c:\\BrainT1Slice.png
Output FileName  --> c:\\BrainT1Slice_output.png
 
Command Line paramters are used as --> 
c:\\BrainT1Slice.png  0.02 20  c:\\BrainT1Slice_thresholdLevelSet.png 10 128 10 -1 1 -1 -1 -1 -1 -1 -1 0.3 30  c:\\BrainT1Slice_op.png
 
int main( int argc, char *argv[] )
{
 FILE *fp = fopen("c:\\check.txt", "w+");
 if(NULL != fp ){
  fprintf(fp,"argv[1] Input File Name --> %s \n", argv[1]);
  fprintf(fp,"argv[2] RMS Error --> %s \n", argv[2]);
  fprintf(fp,"argv[3] Maximum Number Of Iterations--> %s \n", argv[3]);
  fprintf(fp,"argv[4] Input File #2 --> %s \n", argv[4]);
  fprintf(fp,"argv[5] Variance --> %s \n", argv[5]);
  fprintf(fp,"argv[6] Iso-Surface Value --> %s \n", argv[6]);
  fprintf(fp,"argv[7] Lower Threshold --> %s \n", argv[7]);
  fprintf(fp,"argv[8] Upper Threshold --> %s \n", argv[8]);
  fprintf(fp,"argv[9] AdvectionScaling--> %s \n", argv[9]);
  fprintf(fp,"argv[10] SeedX --> %s \n", argv[10]);
  fprintf(fp,"argv[11] SeedY --> %s \n", argv[11]);
  fprintf(fp,"argv[12] X-Radius/InitialDistance--> %s \n", argv[12]);
  fprintf(fp,"argv[13] Y-Radius --> %s \n", argv[13]);
  fprintf(fp,"argv[14] SeedX2 --> %s \n", argv[14]);
  fprintf(fp,"argv[15] SeedY2 --> %s \n", argv[15]);
  fprintf(fp,"argv[16] Propagation Scaling --> %s \n", argv[16]);
  fprintf(fp,"argv[17] Curvature Scaling --> %s \n", argv[17]);
  fprintf(fp,"argv[18] Output File Name --> %s \n", argv[18]);  
 }
 fclose(fp); 
  typedef   float           InternalPixelType;  
  const     unsigned int    Dimension = 2;
  typedef unsigned char OutputPixelType;
  typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
  typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
  typedef itk::BinaryThresholdImageFilter< InternalImageType, OutputImageType > ThresholdingFilterType;
  typedef itk::ImageFileReader< InternalImageType > ReaderType;
  typedef itk::ImageFileWriter<  OutputImageType  > WriterType;  
  typedef   float           InternalPixelType;
  typedef unsigned char OutputPixelType;
  typedef itk::BinaryThresholdImageFilter<InternalImageType, OutputImageType> ThresholdingFilterType;
  ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
    
  float  propgationScale = 0.0, curvatureScale = 0.0;
  typedef  itk::ImageFileReader< InternalImageType > ReaderType;
  typedef  itk::ImageFileWriter<  OutputImageType  > WriterType;
  ReaderType::Pointer reader1 = ReaderType::New();
  ReaderType::Pointer reader2 = ReaderType::New();
  WriterType::Pointer writer = WriterType::New();
  reader1->SetFileName( argv[1] ); // Feature image (smoothed image)
  reader2->SetFileName( argv[4] ); // already segmented initial model 
  writer->SetFileName(  argv[18] ); // output file name   
  thresholder->SetUpperThreshold( 10.0 );
  thresholder->SetLowerThreshold( 0.0 );
  thresholder->SetOutsideValue(  0  );
  thresholder->SetInsideValue(  255 );  
  
  typedef  itk::CannySegmentationLevelSetImageFilter< InternalImageType, 
                InternalImageType > CannySegmentationLevelSetImageFilterType;
  CannySegmentationLevelSetImageFilterType::Pointer cannySegmentation = 
                CannySegmentationLevelSetImageFilterType::New();  
  
  cannySegmentation->SetAdvectionScaling( ::atof(argv[9]) );
  cannySegmentation->SetCurvatureScaling( ::atof(argv[17]) );
  cannySegmentation->SetPropagationScaling( 0.0 );
  // For cases in which some surface expansion is to be allowed, a non-zero value may be set for the
  // propagation term. The propagation term is simply D.  Here,we set it to 0.0    
  // The maximum number of iterations is specified from the command line. It may not be desirable in some 
  // applications to run the filter to convergence.  Only a few iterations may be required.
  
  cannySegmentation->SetMaximumRMSError( ::atof(argv[2]) );
  cannySegmentation->SetNumberOfIterations( ::atoi(argv[3]) );  
  cannySegmentation->SetThreshold( ::atof(argv[7]) );
  cannySegmentation->SetVariance(  ::atof(argv[5]) );  
  cannySegmentation->SetIsoSurfaceValue( ::atof(argv[6]) );  
  cannySegmentation->SetInput( reader2->GetOutput() );
  cannySegmentation->SetFeatureImage( reader1->GetOutput() );
  thresholder->SetInput( cannySegmentation->GetOutput() );  
  writer->SetInput( thresholder->GetOutput() );
  // Examining the propagation (speed) and advection images can help the process of tuning parameters.  
  // These images are available using \code{Set/Get} methods from the filter after it has been updated.
  
  try {
    writer->Update();
  }
  catch( itk::ExceptionObject & excep ) {
    std::cerr << "Exception caught !" << std::endl;
    std::cerr << excep << std::endl;
  }
  // Print useful information
  std::cout << std::endl;
  std::cout << "Max. no. iterations: " << cannySegmentation->GetNumberOfIterations() << std::endl;
  std::cout << "Max. RMS error: " << cannySegmentation->GetMaximumRMSError() << std::endl;
  std::cout << std::endl;
  std::cout << "No. elpased iterations: " << cannySegmentation->GetElapsedIterations() << std::endl;
  std::cout << "RMS change: " << cannySegmentation->GetRMSChange() << std::endl;   
  // Write out the speed (propagation) image for parameter tuning purposes.
  //itk::ImageFileWriter< OutputImageType >::Pointer speedWriter = itk::ImageFileWriter<OutputImageType>::New();  
  itk::ImageFileWriter< InternalImageType >::Pointer speedWriter = itk::ImageFileWriter<InternalImageType>::New();  
  
  speedWriter->SetFileName( "Canny_speedImage.mhd" );  
  speedWriter->SetInput( cannySegmentation->GetSpeedImage()); 
  
  // Since output of LaplacianLevelSet is Float type, we need to rescale it to "unsigned char" (for png).
  /*typedef itk::RescaleIntensityImageFilter< InternalImageType, OutputImageType > RescaleFilterType; 
  RescaleFilterType::Pointer rescaler = RescaleFilterType::New();    
  
  // Set Rescaler Parameters
  rescaler->SetOutputMinimum( 0 ); 
  rescaler->SetOutputMaximum( 255 );  
  
  speedWriter->SetFileName( "Canny_speedImage.mhd" );  
  rescaler->SetInput( cannySegmentation->GetSpeedImage());   
  speedWriter->SetInput( rescaler->GetOutput() );  */
   
  try { speedWriter->Update(); }
  catch( itk::ExceptionObject & excep ){
    std::cerr << "Exception caught !" << std::endl;
    std::cerr << excep << std::endl;
  }   
  return 0;
} // end of  main



		
---------------------------------
Do you Yahoo!?
 Yahoo! Small Business - Try our new resources site! 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20050325/d8fdebe6/attachment.html


More information about the Insight-users mailing list