Hi Camille,<br><br>The problem is that you are creating an empty sample and <br>passing it as input  to the filter method:<br><br>                  filter-&gt;SetInputSample(sample);<br><br>The SetInputSample() method is implemented in the base<br>
class:  itk::SampleAlgorithmBase as<br><br>  void SetInputSample( const TInputSample * sample ) <br>    {<br>    if ( m_InputSample != sample )<br>      {<br>      m_InputSample = sample;<br>      m_MeasurementVectorSize = m_InputSample-&gt;GetMeasurementVectorSize();<br>
      this-&gt;Modified();<br>      }<br>    }<br><br><br>In practice you should populate the sample with data <br>before you pass it to a filter.<br><br>See for example:<br><br>Insight/Testing/Code/Numerics/Statistics/<br>
    itkSampleMeanShiftClusteringFilterTest.cxx<br><br><br>The class that you may want to use is the<br><br>                 ImageToListSampleAdaptor.<br><br><br><br><br>     Regards,<br><br><br>            Luis<br><br><br>
----------------------------------------------------------------------<br><div class="gmail_quote">On Thu, Jul 30, 2009 at 8:57 AM, camille orny <span dir="ltr">&lt;<a href="mailto:camille.orny@gmail.com">camille.orny@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello,<br><br>I am trying to use the itk::SampleMeanShiftBlurringFilter to get, for each pixel, the value of the mode the mean shift algorithm associates it to.<br>
<br>I have written the following code which is compiled without any error reports. Hower I get a &quot;segmentation error&quot; when I execute it. It seems the problem comes from the line  filter-&gt;SetInputSample(sample); when I progressively comment the code.<br>

<br>Are there any problems with that filter ?<br><br>Regards,<br><br>typedef itk::Image&lt; PixelType, 2&gt; TInputImage;<br>typedef itk::Image&lt; PixelType, 2&gt; TOutputImage;<br>typedef itk::Image&lt; unsigned char, 2&gt; TOutputImage2;<br>


typedef otb::ImageFileReader&lt;<div>TInputImage&gt; ReaderType;<br>typedef itk::Statistics::ScalarImageToListAdaptor&lt;TInputImage&gt; SampleType;<br><br></div><div>typedef itk::RescaleIntensityImageFilter&lt;TOutputImage,TOutputImage2&gt; RescalerType;<br>


typedef otb::StreamingImageFileWriter&lt;TOutputImage&gt; WriterType;<br>typedef otb::StreamingImageFileWriter&lt;TOutputImage2&gt; WriterType2;<br></div>//typedef std::vector&lt; int &gt; ClusterLabelsType;<div>
<br>typedef itk::Statistics::SampleMeanShiftBlurringFilter&lt;SampleType&gt; FilterType;<br>
<br></div>//typedef itk::FixedArray&lt;int, 1&gt; TVector;<div><br>//typedef itk::Statistics::ListSample &lt; TVector &gt; ListSampleType;<br><br>ReaderType::Pointer reader=ReaderType::New();<br>SampleType::Pointer sample=SampleType::New();<br>


FilterType::Pointer filter=FilterType::New();<br>WriterType::Pointer writer=WriterType::New();<br>WriterType2::Pointer writer2=WriterType2::New();<br>//RescalerType::Pointer rescaler=RescalerType::New();<br><br>reader-&gt;SetFileName(argv[1]);<br>


reader-&gt;Update();<br>TInputImage::Pointer inimage=reader-&gt;GetOutput();<br><br>sample-&gt;SetImage(inimage);<br><br>filter-&gt;SetInputSample(sample);<br>filter-&gt;Update();<br><br>TOutputImage::Pointer limage=TOutputImage::New();<br>


limage-&gt;CopyInformation(inimage);<br>limage-&gt;SetRegions(limage-&gt;GetLargestPossibleRegion());<br>limage-&gt;Allocate();<br>limage-&gt;FillBuffer(0);<br><br><br>itk::ImageRegionIterator&lt;TOutputImage&gt; lit(limage,limage-&gt;GetLargestPossibleRegion());<br>


lit.GoToBegin();<br> <br><br></div>ListSampleType::Iterator it=(filter-&gt;GetOutput())-&gt;<div>Begin();<br>int i=0;<br><br>std::cout&lt;&lt;&quot;hello&quot;;<br><br>while(!lit.IsAtEnd() )<br><br>
{<br>    std::cout&lt;&lt;&quot;while&quot;;<br>
  lit.Set((filter-&gt;GetOutput())-&gt;GetMeasurementVector(i)[0]);<br>  std::cout&lt;&lt;(filter-&gt;GetOutput())-&gt;GetMeasurementVectorSize();<br>  ++lit;<br>  ++it;<br>  ++i;<br>}<br><br>writer-&gt;SetInput(inimage);<div>

<br>
writer-&gt;SetFileName(argv[2]);<br>writer-&gt;Update();</div></div><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>
Please keep messages on-topic and check the ITK FAQ at: <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></blockquote></div><br>