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

Luis Ibanez luis.ibanez at kitware.com
Sat Apr 2 12:37:06 EST 2005


Hi Conn,


Thanks for posting the output of the two readers.

We tracked this problem down and found that what you are missing is
to invoke the "GenerateSpeedImage()" method in the Canny level set
filter before you invoke GetSpeedImage().

Note that the GenerateSpeedImage() method must be called after
runninig the filter with Update().


For your convinience we added this code to the example in

           Insight/Examples/Segmentation/
               CannySegmentationLevelSetImageFilter.cxx



In order to get the new version simply update your CVS checkout of ITK,
or go to the CVS-Web portal and download the new version of this file:

http://www.itk.org/cgi-bin/viewcvs.cgi/Examples/Segmentation/CannySegmentationLevelSetImageFilter.cxx?rev=1.27&root=Insight&view=log




    Regards,



        Luis



--------------------------
conn sullivan wrote:

> Hello Luis,
>  
> I appreciate your reply.  I use BrainT1Slice.png as input image 
> (smoothed with curvature Anisotropic diffusion) and ventricle output of 
> threshold level set is used as initial model.  I get nice refined image 
> of ventricles, but the speed image (.mhd) is returned with 0 size.
>  
> Attached is the output of reader1 & 2--->getoutput()->print, as you have 
> suggested
> Thanks,
> conn
> 
> */Luis Ibanez <luis.ibanez at kitware.com>/* wrote:
> 
> 
>     Hi Conn,
> 
> 
> 
>     Please try the following first:
> 
> 
>     1) before calling Update() in the writer, invoke
> 
>     reader1->Update();
>     reader2->Update();
> 
> 
>     reader1->GetOutput()->Print( std::cout );
>     reader2->GetOutput()->Print( std::cout );
> 
> 
>     2) then run the program again, and post to the list
>     the result that you get in the standard output.
> 
>     That should help to determine whether the input
>     images are being provided correctly to the
>     canny level set filtetr.
> 
> 
> 
>     Please let us know what you find.
> 
> 
>     Thanks
> 
> 
> 
>     Luis
> 
> 
> 
>     -------------------------
>     conn sullivan wrote:
> 
>      > 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 Scali! ng --> %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
>      > 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::New();
>      > itk::ImageFileWriter< InternalImageType >::Pointer speedWriter =
>      > itk::ImageFileWriter::New();
>      >
>      > speedWriter->SetFileName( "Canny_speedI! mage.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;
>      > }
>     &! gt; return 0;
>      > } // end of main
>      >
>      >





More information about the Insight-users mailing list