<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&#39;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&lt; PixelType, Dimension &gt; ImageType;</div>

<div><br></div><div><span style="white-space:pre-wrap">        </span>typedef itk::ImportImageFilter&lt; PixelType, Dimension &gt; 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-&gt;cols; // size along X</div><div><span style="white-space:pre-wrap">        </span>size[1] = source-&gt;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-&gt;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-&gt;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 &lt; 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&lt;double&gt;( y ) - static_cast&lt;double&gt;(size[1])/2.0;</div>

<div><span style="white-space:pre-wrap">                </span>for(unsigned int x=0; x &lt; size[0]; x++)</div><div><span style="white-space:pre-wrap">                </span>{</div><div><span style="white-space:pre-wrap">                        </span>*it++ = source-&gt;at&lt;float&gt;(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-&gt;SetImportPointer( localBuffer, numberOfPixels, importImageFilterWillOwnTheBuffer );</div><div><span style="white-space:pre-wrap">        </span>importFilter-&gt;Update();</div>

<div><br></div><div><span style="white-space:pre-wrap">        </span>typedef itk::GradientAnisotropicDiffusionImageFilter&lt; ImageType,ImageType &gt; 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-&gt;SetInput(importFilter-&gt;GetOutput());</div><div><span style="white-space:pre-wrap">        </span>const itk::Image&lt; PixelType, Dimension &gt;* test = filter-&gt;GetInput();</div>

<div><span style="white-space:pre-wrap">        </span>filter-&gt;SetNumberOfIterations(iterations);</div><div><span style="white-space:pre-wrap">        </span>filter-&gt;SetTimeStep(0.125);</div><div><span style="white-space:pre-wrap">        </span>filter-&gt;SetConductanceParameter(conductance);</div>

<div><span style="white-space:pre-wrap">        </span>filter-&gt;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 &lt; destination-&gt;cols; x++)</div><div><span style="white-space:pre-wrap">                </span>for(int y = 0; y &lt; destination-&gt;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-&gt;at&lt;float&gt;(y,x) = filter-&gt;GetOutput()-&gt;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-&gt;Delete();</div><div><span style="white-space:pre-wrap">        </span>filter-&gt;Delete();</div>

<div>}</div></div></div>
</div><br></div>