[Insight-users] CannyEdgefilter

Wen Shi wsa18 at sfu.ca
Thu Mar 12 16:35:44 EDT 2009


Hi Ghassan and guys,

As we discussed before, for the cannyedgedetectionfilter, since it deals with noise by first convolve the image with a Guassian filter, 
I supposed that maybe the data from the output filter can be a good measure for the edges.
But when I tried a brain image with the filter, I saw lots of noisy edges in the processed image.
Even in the region in which the original image has nothing(no edge clues there) there, the processed image has a lot of short bright edges.
Why is that?
Did I do anything wrong?
Here is the simple code:

int main(int argc, char* argv[])
{
  argc=3;
	if( argc < 3 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << " inputImage outputImage [variance]" << std::endl;
    return EXIT_FAILURE;
    }
   
  const char * inputFilename  = "BrainProtonDensitySlice.PNG";
  const char * outputFilename = "wire1.jpeg" ;
  float variance = 2.0;

  if( argc > 3 )
    {
    variance = atof( argv[3] );
    }

  typedef unsigned char    CharPixelType;  //  IO
  typedef double           RealPixelType;  //  Operations
  const   unsigned int     Dimension = 2;

  typedef itk::Image<CharPixelType, Dimension>    CharImageType;
  typedef itk::Image<RealPixelType, Dimension>    RealImageType;

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




  

  typedef itk::CastImageFilter< CharImageType, RealImageType> CastToRealFilterType;




  typedef itk::RescaleIntensityImageFilter<RealImageType, CharImageType > RescaleFilter;

  typedef itk::CannyEdgeDetectionImageFilter<RealImageType, RealImageType> CannyFilter;



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

  CastToRealFilterType::Pointer toReal = CastToRealFilterType::New();
  RescaleFilter::Pointer rescale = RescaleFilter::New();

  //Setting the ITK pipeline filter

  CannyFilter::Pointer cannyFilter = CannyFilter::New();

  reader->SetFileName( inputFilename  );
  writer->SetFileName( outputFilename );

  //The output of an edge filter is 0 or 1
  rescale->SetOutputMinimum(   0 );
  rescale->SetOutputMaximum( 255 );

  toReal->SetInput( reader->GetOutput() );

  cannyFilter->SetInput( toReal->GetOutput() );
  cannyFilter->SetVariance( variance );
  rescale->SetInput( cannyFilter->GetOutput() );
  writer->SetInput( rescale->GetOutput() );

  try 
    {
    writer->Update();
    }
  catch( itk::ExceptionObject & err ) 
    { 
    std::cout << "ExceptionObject caught !" << std::endl; 
    std::cout << err << std::endl; 
    return EXIT_FAILURE;
    } 


  return EXIT_SUCCESS;

}


Thanks a lot 

Wen SHi


More information about the Insight-users mailing list