[Insight-users] Access Violation when using itk::GradientAnisotropicDiffusionImageFilter caused by NULL-Pointer

Bradley Lowekamp blowekamp at mail.nih.gov
Thu May 30 10:48:37 EDT 2013


Hello,

I am suspicion that this is related to how you are importing the buffer from OpenCV. Although I don't see anything obvious.

Do you have a full call stack when of when the seg-fault occurs?

Brad

On May 30, 2013, at 3:08 AM, Stephan Fischer <step.fischer at gmail.com> wrote:

> Hi Everyone,
> 
> i have an issue using the itk::GradientAnisotropicDiffusionImageFilter, which ends up crashing in an access violation.
> 
> The function is used to convert an OpenCV image to an itk::Image, smoothing the image with the Perona-Malik-Filter and convert it back to an OpenCV image.
> 
> When i run the Update() function the program ended up in an access violation, caused by a NULL-Pointer in the xtree-file in line 807:
> 
> iterator begin()
> 		{	// return iterator for beginning of mutable sequence
> 		return (iterator(_Lmost(), this)); //_Lmost() causes an access violation caused by NULL-Pointer reference
> 		}
> 
> I'am using the version 4.3 of ITK.
> 
> Any help or advices are appreciated.
> Best regards.
> 
> P.S.:
> 
> The code i am using is the following:
> 
> void PeronaMalikFilter(Mat *source, Mat *destination, int iterations, float conductance)
> {
> 	typedef float PixelType;
> 	const unsigned int Dimension = 2;
> 	typedef itk::Image< PixelType, Dimension > ImageType;
> 
> 	typedef itk::ImportImageFilter< PixelType, Dimension > ImportFilterType;
> 	ImportFilterType::Pointer importFilter = ImportFilterType::New();
> 
> 	ImportFilterType::SizeType size;
> 	size[0] = source->cols; // size along X
> 	size[1] = source->rows; // size along Y
> 	ImportFilterType::IndexType start;
> 	start.Fill( 0 );
> 	ImportFilterType::RegionType region;
> 	region.SetIndex( start );
> 	region.SetSize( size );
> 	importFilter->SetRegion( region );
> 
> 	double origin[ Dimension ];
> 	origin[0] = 0.0; // X coordinate
> 	origin[1] = 0.0; // Y coordinate
> 	importFilter->SetOrigin( origin );
> 
> 	const unsigned int numberOfPixels = size[0] * size[1];
> 	PixelType * localBuffer = new PixelType[ numberOfPixels ];
> 
> 	PixelType * it = localBuffer;
> 	for(unsigned int y=0; y < size[1]; y++)
> 	{
> 		const double dy = static_cast<double>( y ) - static_cast<double>(size[1])/2.0;
> 		for(unsigned int x=0; x < size[0]; x++)
> 		{
> 			*it++ = source->at<float>(y,x);
> 		}
> 	}
> 
> 	const bool importImageFilterWillOwnTheBuffer = true;
> 	importFilter->SetImportPointer( localBuffer, numberOfPixels, importImageFilterWillOwnTheBuffer );
> 	importFilter->Update();
> 
> 	typedef itk::GradientAnisotropicDiffusionImageFilter< ImageType,ImageType > FilterType;
> 	FilterType::Pointer filter = FilterType::New();
> 	filter->SetInput(importFilter->GetOutput());
> 	const itk::Image< PixelType, Dimension >* test = filter->GetInput();
> 	filter->SetNumberOfIterations(iterations);
> 	filter->SetTimeStep(0.125);
> 	filter->SetConductanceParameter(conductance);
> 	filter->Update();
> 
> 	//Fill OpenCV image with ITK image data.
> 	ImageType::IndexType pixelIndex;
> 	for(int x= 0; x < destination->cols; x++)
> 		for(int y = 0; y < destination->rows; y++)
> 		{
> 			pixelIndex[0]=x; pixelIndex[1]=y;
> 			destination->at<float>(y,x) = filter->GetOutput()->GetPixel(pixelIndex);
> 		}
> 	
> 	importFilter->Delete();
> 	filter->Delete();
> }
> 
> _____________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
> 
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users



More information about the Insight-users mailing list