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