[ITK Community] [Insight-users] Problem with ROI filter in a multithread filter

Andrea Valsecchi valsecchi.andrea at gmail.com
Wed Nov 13 10:12:35 EST 2013


I'm writing a multiple thread version of a custom filter. It uses a ROI
filter to extract a 3x3x3 region of the input image. The center of this ROI
is moved through the input image in a loop. If I run the code with a single
thread, it works correctly. If I use more threads I get segmentation fault
after the first iteration, i.e. when I reuse the ROI filter.

I've tried using a different instance of the ROI filter at each iteration,
saving the output of the filter to an image and calling DisconnectPipeline,
calling Modified(), Update(), UpdateLargestPossibleRegion(), replacing the
ROI filter with an Extract Image filter, but none of this worked. What am I
doing wrong? I'm using ITK 4.2


template<class TImage>
void myFilter<TImage>
::ThreadedGenerateData(const typename Superclass::OutputImageRegionType&
outputRegionForThread, ThreadIdType threadId)
{
  typename TImage::ConstPointer input = this->GetInput();
  typename TImage::Pointer output = this->GetOutput();
  typedef typename itk::RegionOfInterestFilter<TImage, TImage> roiType;

  typename roiType::Pointer roi = roiType::New();
  roi->SetInput(input);

  typename TImage::RegionType window;
  typename TImage::RegionType::SizeType size;
  size.Fill(3); //window size=3x3x3
  window.SetSize(size);
  typename TImage::IndexType pi; //pixel index

  itk::ImageRegionIteratorWithIndex<TImage> out(output,
outputRegionForThread);

  // typename TImage::Pointer buffer;

  for(; !out.IsAtEnd(); ++out)
  {
    pi = out.GetIndex();

    window.SetIndex(0, pi[0]-1);
    window.SetIndex(1, pi[1]-1);
    window.SetIndex(2, pi[2]-1);

    if ( outputRegionForThread.IsInside( window ) )
    {
      try
      {
        // typename roiType::Pointer roi = roiType::New();
        roi->SetInput(input);
        roi->SetExtractionRegion(window);
        // roi->SetNumberOfThreads(1);
        // roi->Modified();
        roi->Update();
        // roi->UpdateLargestPossibleRegion();
        // roi->Update();
        // buffer = roi->GetOutput();
        // buffer->Update();
        // buffer->DisconnectPipeline();
      }
      catch( itk::ExceptionObject & err )
      {
        std::cerr << "ExceptionObject caught !" << std::endl;
        std::cerr << err << std::endl;
        return;
      }
    }
  }
}


-- 
Andrea

-- 
Andrea Valsecchi

Postdoctoral Researcher
European Centre for Soft Computing

Edificio de Investigación
Calle Gonzalo Gutiérrez Quirós s/n
33600 Mieres, Asturias, Spain

Telephone: +34 985456545
Fax: +34 985456699
Email: andrea.valsecchi at softcomputing.es
Web: http://www.softcomputing.es
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20131113/a1bf1e1b/attachment-0001.html>
-------------- next part --------------
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

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


More information about the Community mailing list