[Insight-users] Mean Shift Blurring Filter

Luis Ibanez luis.ibanez at kitware.com
Sat Aug 8 19:28:18 EDT 2009


Hi Camille,

The problem is that you are creating an empty sample and
passing it as input  to the filter method:

                  filter->SetInputSample(sample);

The SetInputSample() method is implemented in the base
class:  itk::SampleAlgorithmBase as

  void SetInputSample( const TInputSample * sample )
    {
    if ( m_InputSample != sample )
      {
      m_InputSample = sample;
      m_MeasurementVectorSize = m_InputSample->GetMeasurementVectorSize();
      this->Modified();
      }
    }


In practice you should populate the sample with data
before you pass it to a filter.

See for example:

Insight/Testing/Code/Numerics/Statistics/
    itkSampleMeanShiftClusteringFilterTest.cxx


The class that you may want to use is the

                 ImageToListSampleAdaptor.




     Regards,


            Luis


----------------------------------------------------------------------
On Thu, Jul 30, 2009 at 8:57 AM, camille orny <camille.orny at gmail.com>wrote:

> Hello,
>
> 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.
>
> I have written the following code which is compiled without any error
> reports. Hower I get a "segmentation error" when I execute it. It seems the
> problem comes from the line  filter->SetInputSample(sample); when I
> progressively comment the code.
>
> Are there any problems with that filter ?
>
> Regards,
>
> typedef itk::Image< PixelType, 2> TInputImage;
> typedef itk::Image< PixelType, 2> TOutputImage;
> typedef itk::Image< unsigned char, 2> TOutputImage2;
> typedef otb::ImageFileReader<TInputImage> ReaderType;
> typedef itk::Statistics::ScalarImageToListAdaptor<TInputImage> SampleType;
>
> typedef itk::RescaleIntensityImageFilter<TOutputImage,TOutputImage2>
> RescalerType;
> typedef otb::StreamingImageFileWriter<TOutputImage> WriterType;
> typedef otb::StreamingImageFileWriter<TOutputImage2> WriterType2;
> //typedef std::vector< int > ClusterLabelsType;
> typedef itk::Statistics::SampleMeanShiftBlurringFilter<SampleType>
> FilterType;
>
> //typedef itk::FixedArray<int, 1> TVector;
> //typedef itk::Statistics::ListSample < TVector > ListSampleType;
>
> ReaderType::Pointer reader=ReaderType::New();
> SampleType::Pointer sample=SampleType::New();
> FilterType::Pointer filter=FilterType::New();
> WriterType::Pointer writer=WriterType::New();
> WriterType2::Pointer writer2=WriterType2::New();
> //RescalerType::Pointer rescaler=RescalerType::New();
>
> reader->SetFileName(argv[1]);
> reader->Update();
> TInputImage::Pointer inimage=reader->GetOutput();
>
> sample->SetImage(inimage);
>
> filter->SetInputSample(sample);
> filter->Update();
>
> TOutputImage::Pointer limage=TOutputImage::New();
> limage->CopyInformation(inimage);
> limage->SetRegions(limage->GetLargestPossibleRegion());
> limage->Allocate();
> limage->FillBuffer(0);
>
>
> itk::ImageRegionIterator<TOutputImage>
> lit(limage,limage->GetLargestPossibleRegion());
> lit.GoToBegin();
>
>
> ListSampleType::Iterator it=(filter->GetOutput())->Begin();
> int i=0;
>
> std::cout<<"hello";
>
> while(!lit.IsAtEnd() )
>
> {
>     std::cout<<"while";
>   lit.Set((filter->GetOutput())->GetMeasurementVector(i)[0]);
>   std::cout<<(filter->GetOutput())->GetMeasurementVectorSize();
>   ++lit;
>   ++it;
>   ++i;
> }
>
> writer->SetInput(inimage);
> writer->SetFileName(argv[2]);
> writer->Update();
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090808/be739868/attachment-0001.htm>


More information about the Insight-users mailing list