<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&lt;class TImage&gt;</div><div>void epxFilter&lt;TImage&gt;::BeforeThreadedGenerateData()</div>
<div>{</div><div><span class="" style="white-space:pre">        </span>typedef itk::DiscreteGaussianImageFilter&lt; TImage, TImage &gt; 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-&gt;SetInput( this-&gt;GetInput() ); </div><div><span class="" style="white-space:pre">        </span>gaussianF-&gt;SetVariance(0.5); </div><div><span class="" style="white-space:pre">        </span>gaussianF-&gt;SetMaximumKernelWidth(5);</div>
<div><span class="" style="white-space:pre">        </span>gaussianF-&gt;SetNumberOfThreads(10); </div><div><span class="" style="white-space:pre">        </span>gaussianF-&gt;Update(); </div><div>}</div><div><br></div><div><div>template&lt;class TImage&gt;</div>
<div>void epxFilter&lt;TImage&gt;::AfterThreadedGenerateData()</div><div>{</div><div><span class="" style="white-space:pre">        </span>typename TImage::Pointer output = this-&gt;GetOutput();</div><div><span class="" style="white-space:pre">        </span></div>
<div><span class="" style="white-space:pre">        </span>typedef itk::ConnectedThresholdImageFilter&lt;TImage, TImage&gt; 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-&gt;SetInput(output); </div><div><span class="" style="white-space:pre">        </span>connectorF-&gt;SetLower(254); </div>
<div><span class="" style="white-space:pre">        </span>connectorF-&gt;SetUpper(256); </div><div><span class="" style="white-space:pre">        </span>connectorF-&gt;SetReplaceValue(255);</div><div><span class="" style="white-space:pre">        </span>//connectorF-&gt;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-&gt;AddSeed(seed);</div><div><span class="" style="white-space:pre">        </span></div><div>
<span class="" style="white-space:pre">        </span>connectorF-&gt;Update(); </div><div>}</div></div><div> </div><div>template&lt;class TImage&gt;</div><div>void epxFilter&lt;TImage&gt;</div><div>::ThreadedGenerateData(const OutputImageRegionType &amp; outputRegionForThread, ThreadIdType threadId)</div>
<div>{</div><div>  typename TImage::ConstPointer input = this-&gt;GetInput();</div><div>  typename TImage::Pointer output = this-&gt;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&lt;TImage&gt; out(output, outputRegionForThread);</div>
<div>  itk::ConstNeighborhoodIterator&lt;TImage&gt; 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 &gt; -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 &gt; airsense) || (tagValue &gt; 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>