<div dir="ltr">Hi Everyone,<br><div class="gmail_quote"><div dir="ltr"><div><br></div><div>i have an issue using the itk::GradientAnisotropicDiffusionImageFilter, which ends up crashing in an access violation.</div><div><br>
</div><div>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.</div>
<div><br></div><div>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:</div><div><br></div><div><div>iterator begin()</div>
<div><span style="white-space:pre-wrap">                </span>{<span style="white-space:pre-wrap">        </span>// return iterator for beginning of mutable sequence</div><div><span style="white-space:pre-wrap">                </span>return (iterator(_Lmost(), this)); //_Lmost() causes an access violation caused by NULL-Pointer reference</div>
<div><span style="white-space:pre-wrap">                </span>}</div></div><div><br></div><div>I'am using the version 4.3 of ITK.</div><div><br></div><div>Any help or advices are appreciated.</div><div>
Best regards.</div><div><br></div><div>P.S.:</div><div><br></div><div>The code i am using is the following:</div><div><br></div><div><div>void PeronaMalikFilter(Mat *source, Mat *destination, int iterations, float conductance)</div>
<div>{</div><div><span style="white-space:pre-wrap">        </span>typedef float PixelType;</div><div><span style="white-space:pre-wrap">        </span>const unsigned int Dimension = 2;</div><div><span style="white-space:pre-wrap">        </span>typedef itk::Image< PixelType, Dimension > ImageType;</div>
<div><br></div><div><span style="white-space:pre-wrap">        </span>typedef itk::ImportImageFilter< PixelType, Dimension > ImportFilterType;</div><div><span style="white-space:pre-wrap">        </span>ImportFilterType::Pointer importFilter = ImportFilterType::New();</div>
<div><br></div><div><span style="white-space:pre-wrap">        </span>ImportFilterType::SizeType size;</div><div><span style="white-space:pre-wrap">        </span>size[0] = source->cols; // size along X</div><div><span style="white-space:pre-wrap">        </span>size[1] = source->rows; // size along Y</div>
<div><span style="white-space:pre-wrap">        </span>ImportFilterType::IndexType start;</div><div><span style="white-space:pre-wrap">        </span>start.Fill( 0 );</div><div><span style="white-space:pre-wrap">        </span>ImportFilterType::RegionType region;</div>
<div><span style="white-space:pre-wrap">        </span>region.SetIndex( start );</div><div><span style="white-space:pre-wrap">        </span>region.SetSize( size );</div><div><span style="white-space:pre-wrap">        </span>importFilter->SetRegion( region );</div>
<div><br></div><div><span style="white-space:pre-wrap">        </span>double origin[ Dimension ];</div><div><span style="white-space:pre-wrap">        </span>origin[0] = 0.0; // X coordinate</div><div><span style="white-space:pre-wrap">        </span>origin[1] = 0.0; // Y coordinate</div>
<div><span style="white-space:pre-wrap">        </span>importFilter->SetOrigin( origin );</div><div><br></div><div><span style="white-space:pre-wrap">        </span>const unsigned int numberOfPixels = size[0] * size[1];</div>
<div><span style="white-space:pre-wrap">        </span>PixelType * localBuffer = new PixelType[ numberOfPixels ];</div><div><br></div><div><span style="white-space:pre-wrap">        </span>PixelType * it = localBuffer;</div><div>
<span style="white-space:pre-wrap">        </span>for(unsigned int y=0; y < size[1]; y++)</div><div><span style="white-space:pre-wrap">        </span>{</div><div><span style="white-space:pre-wrap">                </span>const double dy = static_cast<double>( y ) - static_cast<double>(size[1])/2.0;</div>
<div><span style="white-space:pre-wrap">                </span>for(unsigned int x=0; x < size[0]; x++)</div><div><span style="white-space:pre-wrap">                </span>{</div><div><span style="white-space:pre-wrap">                        </span>*it++ = source->at<float>(y,x);</div>
<div><span style="white-space:pre-wrap">                </span>}</div><div><span style="white-space:pre-wrap">        </span>}</div><div><br></div><div><span style="white-space:pre-wrap">        </span>const bool importImageFilterWillOwnTheBuffer = true;</div>
<div><span style="white-space:pre-wrap">        </span>importFilter->SetImportPointer( localBuffer, numberOfPixels, importImageFilterWillOwnTheBuffer );</div><div><span style="white-space:pre-wrap">        </span>importFilter->Update();</div>
<div><br></div><div><span style="white-space:pre-wrap">        </span>typedef itk::GradientAnisotropicDiffusionImageFilter< ImageType,ImageType > FilterType;</div><div><span style="white-space:pre-wrap">        </span>FilterType::Pointer filter = FilterType::New();</div>
<div><span style="white-space:pre-wrap">        </span>filter->SetInput(importFilter->GetOutput());</div><div><span style="white-space:pre-wrap">        </span>const itk::Image< PixelType, Dimension >* test = filter->GetInput();</div>
<div><span style="white-space:pre-wrap">        </span>filter->SetNumberOfIterations(iterations);</div><div><span style="white-space:pre-wrap">        </span>filter->SetTimeStep(0.125);</div><div><span style="white-space:pre-wrap">        </span>filter->SetConductanceParameter(conductance);</div>
<div><span style="white-space:pre-wrap">        </span>filter->Update();</div><div><br></div><div><span style="white-space:pre-wrap">        </span>//Fill OpenCV image with ITK image data.</div><div><span style="white-space:pre-wrap">        </span>ImageType::IndexType pixelIndex;</div>
<div><span style="white-space:pre-wrap">        </span>for(int x= 0; x < destination->cols; x++)</div><div><span style="white-space:pre-wrap">                </span>for(int y = 0; y < destination->rows; y++)</div><div><span style="white-space:pre-wrap">                </span>{</div>
<div><span style="white-space:pre-wrap">                        </span>pixelIndex[0]=x; pixelIndex[1]=y;</div><div><span style="white-space:pre-wrap">                        </span>destination->at<float>(y,x) = filter->GetOutput()->GetPixel(pixelIndex);</div>
<div><span style="white-space:pre-wrap">                </span>}</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>importFilter->Delete();</div><div><span style="white-space:pre-wrap">        </span>filter->Delete();</div>
<div>}</div></div></div>
</div><br></div>