[Insight-users] Multithreading - Before / After

Sergio Aguirre sergio.aguirre at gmail.com
Sat Mar 23 14:32:39 EDT 2013


Hi everyone

I have been using the OilPaintingImageFilter to implement a multi-threaded
filter.

So by implementing my code in the ThreadedGenerateData call I successfully
engage the multiple cores.

However, I would like to use the BeforeThreadedGenerateData and the
AfterThreadedGenerateData to pre-process and post-process the
outputRegionForThread with ITK filters...

How do I input the outputRegionForThread to an ITK filter in the Before
call, send it to the ThreadedGenerateData call and afterwards send the
result to the After call and output the filter?

Code is below

Thank you,
Sergio


template<class TImage>
void epxFilter<TImage>::BeforeThreadedGenerateData()
{
typedef itk::DiscreteGaussianImageFilter< TImage, TImage > GaussianFilter;
typename GaussianFilter::Pointer gaussianF = GaussianFilter::New();
gaussianF->SetInput( this->GetInput() );
gaussianF->SetVariance(0.5);
gaussianF->SetMaximumKernelWidth(5);
gaussianF->SetNumberOfThreads(10);
gaussianF->Update();
}

template<class TImage>
void epxFilter<TImage>::AfterThreadedGenerateData()
{
typename TImage::Pointer output = this->GetOutput();
 typedef itk::ConnectedThresholdImageFilter<TImage, TImage>
ConnectedFilter;
typename ConnectedFilter::Pointer connectorF = ConnectedFilter::New();
connectorF = ConnectedFilter::New();
connectorF->SetInput(output);
connectorF->SetLower(254);
connectorF->SetUpper(256);
connectorF->SetReplaceValue(255);
//connectorF->SetNumberOfThreads(10);
 TImage::IndexType seed;
seed[0] = 122;
seed[1] = 228;
seed[2] = 14;
connectorF->AddSeed(seed);
 connectorF->Update();
}

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

  TImage::SizeType m_Radius;
m_Radius[0] = 1;
m_Radius[1] = 2;
m_Radius[2] = 1;

  itk::ImageRegionIterator<TImage> out(output, outputRegionForThread);
  itk::ConstNeighborhoodIterator<TImage> it(m_Radius, input,
outputRegionForThread);

  TImage::PixelType imageValue;
float airValue;
float tagValue;
float borderValue;
float min = 100000000.0;
float max = 0.0;

  while(!out.IsAtEnd())
  {
typename TImage::ValueType vxl = it.GetCenterPixel();

if (vxl > -1025)
{
airValue = mAirProb(vxl);
tagValue = mTagProb(vxl);
 if ( (airValue > airsense) || (tagValue > tagsense) )
out.Set(255);
else
out.Set(0);
}

    ++it;
    ++out;
  }

}

}// end namespace
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130323/881573a9/attachment.htm>


More information about the Insight-users mailing list