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

Matt McCormick matt.mccormick at kitware.com
Wed Nov 13 12:55:26 EST 2013


Hi Andrea,

Getting a stack trace in a debugger should help.  Also, I see the check

  if ( outputRegionForThread.IsInside( window ) )

but no check to see if "window" is inside the BufferedRegion of the Input.

For this specific use case, NeighborhoodIterator's (see the ITK
Software Guide) would be much more efficient.

Hope this helps,
Matt

On Wed, Nov 13, 2013 at 10:12 AM, Andrea Valsecchi
<valsecchi.andrea at gmail.com> wrote:
> 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
>
>
> _____________________________________
> 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 Insight-users mailing list