[Insight-users] error using Canny edge detection filter

Aime Alvarez aime_alvarez at yahoo.com
Tue Sep 27 05:47:00 EDT 2005


Hello:
I am trying to integrate itK code inside my
application. I do some processing upon an image and
then I want to extract edges from this image using the
itkCannyEdgeDetectionImageFilter. I read Tutorial
"Getting Started V: Integrating ITK in your
Application" and review the "Canny Edge Detection"
example in 6.2.1 of the ItkSoftwareGuide-2.0.0.pdf. I
think that I'm doing right things but I am getting an
error of "Access violation" when I call the Update()
of the Canny filter. My code is at the end of the
message, hope you can help me to see the details that
I can´t see. 

	rows = /* Get rows from the input image*/
	cols = /* Get cols from the input image*/

	typedef itk::Image< float, 2 > ImageType;
	ImageType::Pointer image = ImageType::New();

	//Copying data from input image to itk image
	ImageType::RegionType 			region; 
	ImageType::RegionType::IndexType	index;
	ImageType::RegionType::SizeType		size;

	index.Fill( 0 ); 
	size[1] = rows;		//rows of matrix
	size[0] = cols;		//cols of matrix

	region.SetIndex( index );
	region.SetSize( size );

	// Set the regions and allocate
	image->SetRegions( region );
	image->Allocate();

	double spacing[2];
	spacing[0] = 1.0;
	spacing[1] = 1.0;
	
	image->SetSpacing( spacing );
	
	double origin[2];
	origin[0] = 0;
	origin[1] = 0;
	image->SetOrigin( origin );
	image->FillBuffer(0.0);

	typedef itk::ImageRegionIterator< ImageType >
IteratorType;
	IteratorType imageIt( image, region );

	imageIt.GoToBegin();
	for ( int j, i = 0; i < rows; i++ )
		for ( j = 0; j < cols; j++ )
		{
			pix = /* Get pixel located in position (i,j) of the
matrix of pixels */;
			imageIt.Set( pix );
			++imageIt;
		}


	// I test the finest of the process of copying the
image data by
	// saving the itk image using
RescaleIntensityImageFilter and ImageFileWriter
	// and it works OK
	
	typedef itk::CannyEdgeDetectionImageFilter<ImageType,
ImageType> CannyFilterType;
	CannyFilterType::Pointer cannyFilter =
CannyFilterType::New();

	// Setting parameters
	cannyFilter->SetInput( image );
	/* the variance is read from user input */
	cannyFilter->SetVariance( Variance ); 
	try
	{
		cannyFilter->Update();
	}
	catch( itk::ExceptionObject & err ) 
    	{ 
    	std::cout << "ExceptionObject caught !" <<
std::endl; 
    	std::cout << err << std::endl; 
    	return;
    	} 





		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com


More information about the Insight-users mailing list