<div dir="ltr">Hi everyone <div><br></div><div style>I have been using the OilPaintingImageFilter to implement a multi-threaded filter. </div><div style><br></div><div style>So by implementing my code in the ThreadedGenerateData call I successfully engage the multiple cores. </div>
<div style><br></div><div style>However, I would like to use the BeforeThreadedGenerateData and the AfterThreadedGenerateData to pre-process and post-process the outputRegionForThread with ITK filters... </div><div style>
<br></div><div style>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? </div><div style>
<br></div><div style>Code is below </div><div style><br></div><div style>Thank you, <br>Sergio </div><div style><br></div><div style><br></div><div style><div>template<class TImage></div><div>void epxFilter<TImage>::BeforeThreadedGenerateData()</div>
<div>{</div><div><span class="" style="white-space:pre">        </span>typedef itk::DiscreteGaussianImageFilter< TImage, TImage > GaussianFilter; </div><div><span class="" style="white-space:pre">        </span>typename GaussianFilter::Pointer gaussianF = GaussianFilter::New(); </div>
<div><span class="" style="white-space:pre">        </span>gaussianF->SetInput( this->GetInput() ); </div><div><span class="" style="white-space:pre">        </span>gaussianF->SetVariance(0.5); </div><div><span class="" style="white-space:pre">        </span>gaussianF->SetMaximumKernelWidth(5);</div>
<div><span class="" style="white-space:pre">        </span>gaussianF->SetNumberOfThreads(10); </div><div><span class="" style="white-space:pre">        </span>gaussianF->Update(); </div><div>}</div><div><br></div><div><div>template<class TImage></div>
<div>void epxFilter<TImage>::AfterThreadedGenerateData()</div><div>{</div><div><span class="" style="white-space:pre">        </span>typename TImage::Pointer output = this->GetOutput();</div><div><span class="" style="white-space:pre">        </span></div>
<div><span class="" style="white-space:pre">        </span>typedef itk::ConnectedThresholdImageFilter<TImage, TImage> ConnectedFilter; </div><div><span class="" style="white-space:pre">        </span>typename ConnectedFilter::Pointer connectorF = ConnectedFilter::New(); </div>
<div><span class="" style="white-space:pre">        </span>connectorF = ConnectedFilter::New(); </div><div><span class="" style="white-space:pre">        </span>connectorF->SetInput(output); </div><div><span class="" style="white-space:pre">        </span>connectorF->SetLower(254); </div>
<div><span class="" style="white-space:pre">        </span>connectorF->SetUpper(256); </div><div><span class="" style="white-space:pre">        </span>connectorF->SetReplaceValue(255);</div><div><span class="" style="white-space:pre">        </span>//connectorF->SetNumberOfThreads(10); </div>
<div><span class="" style="white-space:pre">        </span></div><div><span class="" style="white-space:pre">        </span>TImage::IndexType seed; </div><div><span class="" style="white-space:pre">        </span>seed[0] = 122; </div><div><span class="" style="white-space:pre">        </span>seed[1] = 228;</div>
<div><span class="" style="white-space:pre">        </span>seed[2] = 14;</div><div><span class="" style="white-space:pre">        </span>connectorF->AddSeed(seed);</div><div><span class="" style="white-space:pre">        </span></div><div>
<span class="" style="white-space:pre">        </span>connectorF->Update(); </div><div>}</div></div><div> </div><div>template<class TImage></div><div>void epxFilter<TImage></div><div>::ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, ThreadIdType threadId)</div>
<div>{</div><div> typename TImage::ConstPointer input = this->GetInput();</div><div> typename TImage::Pointer output = this->GetOutput();</div><div> </div><div> TImage::SizeType m_Radius;</div><div><span class="" style="white-space:pre">        </span>m_Radius[0] = 1;</div>
<div><span class="" style="white-space:pre">        </span>m_Radius[1] = 2;</div><div><span class="" style="white-space:pre">        </span>m_Radius[2] = 1; </div><div> </div><div> itk::ImageRegionIterator<TImage> out(output, outputRegionForThread);</div>
<div> itk::ConstNeighborhoodIterator<TImage> it(m_Radius, input, outputRegionForThread);</div><div> </div><div> TImage::PixelType imageValue;</div><div><span class="" style="white-space:pre">        </span>float airValue; </div>
<div><span class="" style="white-space:pre">        </span>float tagValue; </div><div><span class="" style="white-space:pre">        </span>float borderValue; </div><div><span class="" style="white-space:pre">        </span>float min = 100000000.0; </div>
<div><span class="" style="white-space:pre">        </span>float max = 0.0;</div><div> </div><div> while(!out.IsAtEnd())</div><div> {</div><div><span class="" style="white-space:pre">        </span>typename TImage::ValueType vxl = it.GetCenterPixel();</div>
<div><br></div><div><span class="" style="white-space:pre">        </span>if (vxl > -1025)</div><div><span class="" style="white-space:pre">        </span>{</div><div><span class="" style="white-space:pre">                </span>airValue = mAirProb(vxl); </div>
<div><span class="" style="white-space:pre">                </span>tagValue = mTagProb(vxl);</div><div><span class="" style="white-space:pre">                </span></div><div><span class="" style="white-space:pre">                </span>if ( (airValue > airsense) || (tagValue > tagsense) )</div>
<div><span class="" style="white-space:pre">                        </span>out.Set(255);</div><div><span class="" style="white-space:pre">                </span>else </div><div><span class="" style="white-space:pre">                        </span>out.Set(0); </div><div><span class="" style="white-space:pre">        </span>}</div>
<div> </div><div> ++it;</div><div> ++out;</div><div> }</div><div><br></div><div>}</div><div> </div><div>}// end namespace</div></div></div>