<div dir="ltr">@Bill <div>its the filter-&gt;Update() function;</div><div><br></div><div>@Bradley</div><div>Unfortunatlly i can&#39;t give you a strack trace anymore. I updated my project with the sources from the git repository. Now the error is gone. </div>
<div>I also have discovered that there is an itkOpenCVBridge class. </div><div>So i made a test with my code that is posted at the end and the bridge class.</div><div>It turned out that my code is working now.</div><div style>
But the itkOpenCVBridge class throws an error while it is importing the data.</div><div><br></div><div style>For completion and for other users here the full function:</div><div style><br></div><div style><div>void PeronaMalikFilterITK(Mat *source, Mat *destination, int iterations, float conductance)</div>
<div>{</div><div><span class="" style="white-space:pre">        </span>typedef float PixelType;</div><div><span class="" style="white-space:pre">        </span>const unsigned int Dimension = 2;</div><div><span class="" style="white-space:pre">        </span>typedef itk::Image&lt; PixelType, Dimension &gt; ImageType;</div>
<div><br></div><div><span class="" style="white-space:pre">        </span>typedef itk::ImportImageFilter&lt; PixelType, Dimension &gt; ImportFilterType;</div><div><span class="" style="white-space:pre">        </span>ImportFilterType::Pointer importFilter = ImportFilterType::New();</div>
<div><br></div><div><span class="" style="white-space:pre">        </span>ImportFilterType::SizeType size;</div><div><span class="" style="white-space:pre">        </span>size[0] = source-&gt;cols; // size along X</div><div><span class="" style="white-space:pre">        </span>size[1] = source-&gt;rows; // size along Y</div>
<div><span class="" style="white-space:pre">        </span>ImportFilterType::IndexType start;</div><div><span class="" style="white-space:pre">        </span>start.Fill( 0 );</div><div><span class="" style="white-space:pre">        </span>ImportFilterType::RegionType region;</div>
<div><span class="" style="white-space:pre">        </span>region.SetIndex( start );</div><div><span class="" style="white-space:pre">        </span>region.SetSize( size );</div><div><span class="" style="white-space:pre">        </span>importFilter-&gt;SetRegion( region );</div>
<div><br></div><div><span class="" style="white-space:pre">        </span>double origin[ Dimension ];</div><div><span class="" style="white-space:pre">        </span>origin[0] = 0.0; // X coordinate</div><div><span class="" style="white-space:pre">        </span>origin[1] = 0.0; // Y coordinate</div>
<div><span class="" style="white-space:pre">        </span>importFilter-&gt;SetOrigin( origin );</div><div><br></div><div><span class="" style="white-space:pre">        </span>const unsigned int numberOfPixels = size[0] * size[1];</div>
<div><span class="" style="white-space:pre">        </span>PixelType * localBuffer = new PixelType[ numberOfPixels ];</div><div><br></div><div><span class="" style="white-space:pre">        </span>PixelType * it = localBuffer;</div><div>
<span class="" style="white-space:pre">        </span>for(unsigned int y=0; y &lt; size[1]; y++)</div><div><span class="" style="white-space:pre">        </span>{</div><div><span class="" style="white-space:pre">                </span>const double dy = static_cast&lt;double&gt;( y ) - static_cast&lt;double&gt;(size[1])/2.0;</div>
<div><span class="" style="white-space:pre">                </span>for(unsigned int x=0; x &lt; size[0]; x++)</div><div><span class="" style="white-space:pre">                </span>{</div><div><span class="" style="white-space:pre">                        </span>*it++ = source-&gt;at&lt;float&gt;(y,x);</div>
<div><span class="" style="white-space:pre">                </span>}</div><div><span class="" style="white-space:pre">        </span>}</div><div><br></div><div><span class="" style="white-space:pre">        </span>const bool importImageFilterWillOwnTheBuffer = true;</div>
<div><span class="" style="white-space:pre">        </span>importFilter-&gt;SetImportPointer( localBuffer, numberOfPixels, importImageFilterWillOwnTheBuffer );</div><div><span class="" style="white-space:pre">        </span>importFilter-&gt;Update();</div>
<div><br></div><div><span class="" style="white-space:pre">        </span>typedef itk::GradientAnisotropicDiffusionImageFilter&lt; ImageType,ImageType &gt; FilterType;</div><div><span class="" style="white-space:pre">        </span>FilterType::Pointer filter = FilterType::New();</div>
<div><span class="" style="white-space:pre">        </span>filter-&gt;SetInput(importFilter-&gt;GetOutput());</div><div><span class="" style="white-space:pre">        </span>filter-&gt;SetNumberOfIterations(iterations);</div><div><span class="" style="white-space:pre">        </span>filter-&gt;SetTimeStep(0.125);</div>
<div><span class="" style="white-space:pre">        </span>filter-&gt;SetConductanceParameter(conductance);</div><div><span class="" style="white-space:pre">        </span>filter-&gt;Update();</div><div><br></div><div><span class="" style="white-space:pre">        </span>//Fill OpenCV image with ITK image data.</div>
<div><span class="" style="white-space:pre">        </span>//Inefficient</div><div><span class="" style="white-space:pre">        </span>ImageType::IndexType pixelIndex;</div><div><span class="" style="white-space:pre">        </span>for(int x= 0; x &lt; destination-&gt;cols; x++)</div>
<div><span class="" style="white-space:pre">                </span>for(int y = 0; y &lt; destination-&gt;rows; y++)</div><div><span class="" style="white-space:pre">                </span>{</div><div><span class="" style="white-space:pre">                        </span>pixelIndex[0]=x; pixelIndex[1]=y;</div>
<div><span class="" style="white-space:pre">                        </span>destination-&gt;at&lt;float&gt;(y,x) = filter-&gt;GetOutput()-&gt;GetPixel(pixelIndex);</div><div><span class="" style="white-space:pre">                </span>}</div><div>}</div></div>

<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/5/30 Bill Lorensen <span dir="ltr">&lt;<a href="mailto:bill.lorensen@gmail.com" target="_blank">bill.lorensen@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Which Update()?<br><br></div><div class="gmail_extra"><div><div class="h5"><br><br><div class="gmail_quote">
On Thu, May 30, 2013 at 10:48 AM, Bradley Lowekamp <span dir="ltr">&lt;<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello,<br>
<br>
I am suspicion that this is related to how you are importing the buffer from OpenCV. Although I don&#39;t see anything obvious.<br>
<br>
Do you have a full call stack when of when the seg-fault occurs?<br>
<br>
Brad<br>
<div><div><br>
On May 30, 2013, at 3:08 AM, Stephan Fischer &lt;<a href="mailto:step.fischer@gmail.com" target="_blank">step.fischer@gmail.com</a>&gt; wrote:<br>
<br>
&gt; Hi Everyone,<br>
&gt;<br>
&gt; i have an issue using the itk::GradientAnisotropicDiffusionImageFilter, which ends up crashing in an access violation.<br>
&gt;<br>
&gt; 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.<br>
&gt;<br>
&gt; 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:<br>
&gt;<br>
&gt; iterator begin()<br>
&gt;               {       // return iterator for beginning of mutable sequence<br>
&gt;               return (iterator(_Lmost(), this)); //_Lmost() causes an access violation caused by NULL-Pointer reference<br>
&gt;               }<br>
&gt;<br>
&gt; I&#39;am using the version 4.3 of ITK.<br>
&gt;<br>
&gt; Any help or advices are appreciated.<br>
&gt; Best regards.<br>
&gt;<br>
&gt; P.S.:<br>
&gt;<br>
&gt; The code i am using is the following:<br>
&gt;<br>
&gt; void PeronaMalikFilter(Mat *source, Mat *destination, int iterations, float conductance)<br>
&gt; {<br>
&gt;       typedef float PixelType;<br>
&gt;       const unsigned int Dimension = 2;<br>
&gt;       typedef itk::Image&lt; PixelType, Dimension &gt; ImageType;<br>
&gt;<br>
&gt;       typedef itk::ImportImageFilter&lt; PixelType, Dimension &gt; ImportFilterType;<br>
&gt;       ImportFilterType::Pointer importFilter = ImportFilterType::New();<br>
&gt;<br>
&gt;       ImportFilterType::SizeType size;<br>
&gt;       size[0] = source-&gt;cols; // size along X<br>
&gt;       size[1] = source-&gt;rows; // size along Y<br>
&gt;       ImportFilterType::IndexType start;<br>
&gt;       start.Fill( 0 );<br>
&gt;       ImportFilterType::RegionType region;<br>
&gt;       region.SetIndex( start );<br>
&gt;       region.SetSize( size );<br>
&gt;       importFilter-&gt;SetRegion( region );<br>
&gt;<br>
&gt;       double origin[ Dimension ];<br>
&gt;       origin[0] = 0.0; // X coordinate<br>
&gt;       origin[1] = 0.0; // Y coordinate<br>
&gt;       importFilter-&gt;SetOrigin( origin );<br>
&gt;<br>
&gt;       const unsigned int numberOfPixels = size[0] * size[1];<br>
&gt;       PixelType * localBuffer = new PixelType[ numberOfPixels ];<br>
&gt;<br>
&gt;       PixelType * it = localBuffer;<br>
&gt;       for(unsigned int y=0; y &lt; size[1]; y++)<br>
&gt;       {<br>
&gt;               const double dy = static_cast&lt;double&gt;( y ) - static_cast&lt;double&gt;(size[1])/2.0;<br>
&gt;               for(unsigned int x=0; x &lt; size[0]; x++)<br>
&gt;               {<br>
&gt;                       *it++ = source-&gt;at&lt;float&gt;(y,x);<br>
&gt;               }<br>
&gt;       }<br>
&gt;<br>
&gt;       const bool importImageFilterWillOwnTheBuffer = true;<br>
&gt;       importFilter-&gt;SetImportPointer( localBuffer, numberOfPixels, importImageFilterWillOwnTheBuffer );<br>
&gt;       importFilter-&gt;Update();<br>
&gt;<br>
&gt;       typedef itk::GradientAnisotropicDiffusionImageFilter&lt; ImageType,ImageType &gt; FilterType;<br>
&gt;       FilterType::Pointer filter = FilterType::New();<br>
&gt;       filter-&gt;SetInput(importFilter-&gt;GetOutput());<br>
&gt;       const itk::Image&lt; PixelType, Dimension &gt;* test = filter-&gt;GetInput();<br>
&gt;       filter-&gt;SetNumberOfIterations(iterations);<br>
&gt;       filter-&gt;SetTimeStep(0.125);<br>
&gt;       filter-&gt;SetConductanceParameter(conductance);<br>
&gt;       filter-&gt;Update();<br>
&gt;<br>
&gt;       //Fill OpenCV image with ITK image data.<br>
&gt;       ImageType::IndexType pixelIndex;<br>
&gt;       for(int x= 0; x &lt; destination-&gt;cols; x++)<br>
&gt;               for(int y = 0; y &lt; destination-&gt;rows; y++)<br>
&gt;               {<br>
&gt;                       pixelIndex[0]=x; pixelIndex[1]=y;<br>
&gt;                       destination-&gt;at&lt;float&gt;(y,x) = filter-&gt;GetOutput()-&gt;GetPixel(pixelIndex);<br>
&gt;               }<br>
&gt;<br>
&gt;       importFilter-&gt;Delete();<br>
&gt;       filter-&gt;Delete();<br>
&gt; }<br>
&gt;<br>
</div></div>&gt; _____________________________________<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; Visit other Kitware open-source projects at<br>
&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;<br>
&gt; Kitware offers ITK Training Courses, for more information visit:<br>
&gt; <a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
&gt;<br>
&gt; Please keep messages on-topic and check the ITK FAQ at:<br>
&gt; <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
<br>
_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</blockquote></div><br><br clear="all"><br></div></div><span class="HOEnZb"><font color="#888888">-- <br>Unpaid intern in BillsBasement at noware dot com<br>
</font></span></div>
</blockquote></div><br></div>