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

Stephan Fischer step.fischer at gmail.com
Thu May 30 03:08:56 EDT 2013


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();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130530/ac6fdfb3/attachment.htm>


More information about the Insight-users mailing list