22 #ifndef __StreamingStatisticsMosaicFilter_hxx
23 #define __StreamingStatisticsMosaicFilter_hxx
30 template <
class TInputImage,
class TOutputImage,
class TInternalValueType>
41 for (
int i = 1; i < 6; ++i)
43 typename RealMatrixListObjectType::Pointer output =
static_cast<RealMatrixListObjectType*
>(this->MakeOutput(i).GetPointer());
44 this->itk::ProcessObject::SetNthOutput(i, output.GetPointer());
51 typename RealMatrixObjectType::Pointer output =
static_cast<RealMatrixObjectType*
>(this->MakeOutput(6).GetPointer());
52 this->itk::ProcessObject::SetNthOutput(6, output.GetPointer());
58 template <
class TInputImage,
class TOutputImage,
class TInternalValueType>
59 typename itk::DataObject::Pointer
62 itkDebugMacro(<<
"Entering MakeOutput(" << output <<
")");
65 return static_cast<itk::DataObject*
>(TOutputImage::New().GetPointer());
69 return static_cast<itk::DataObject*
>(RealMatrixObjectType::New().GetPointer());
71 return static_cast<itk::DataObject*
>(RealMatrixListObjectType::New().GetPointer());
74 template <
class TInputImage,
class TOutputImage,
class TInternalValueType>
81 template <
class TInputImage,
class TOutputImage,
class TInternalValueType>
88 template <
class TInputImage,
class TOutputImage,
class TInternalValueType>
95 template <
class TInputImage,
class TOutputImage,
class TInternalValueType>
102 template <
class TInputImage,
class TOutputImage,
class TInternalValueType>
109 template <
class TInputImage,
class TOutputImage,
class TInternalValueType>
116 template <
class TInputImage,
class TOutputImage,
class TInternalValueType>
120 return static_cast<const RealMatrixListObjectType*
>(this->itk::ProcessObject::GetOutput(1));
123 template <
class TInputImage,
class TOutputImage,
class TInternalValueType>
127 return static_cast<const RealMatrixListObjectType*
>(this->itk::ProcessObject::GetOutput(2));
130 template <
class TInputImage,
class TOutputImage,
class TInternalValueType>
134 return static_cast<const RealMatrixListObjectType*
>(this->itk::ProcessObject::GetOutput(3));
137 template <
class TInputImage,
class TOutputImage,
class TInternalValueType>
141 return static_cast<const RealMatrixListObjectType*
>(this->itk::ProcessObject::GetOutput(4));
144 template <
class TInputImage,
class TOutputImage,
class TInternalValueType>
148 return static_cast<const RealMatrixListObjectType*
>(this->itk::ProcessObject::GetOutput(5));
151 template <
class TInputImage,
class TOutputImage,
class TInternalValueType>
155 return static_cast<const RealMatrixObjectType*
>(this->itk::ProcessObject::GetOutput(6));
161 template <
class TInputImage,
class TOutputImage,
class TInternalValueType>
164 itkDebugMacro(<<
"Entering Reset()");
166 Superclass::GenerateOutputInformation();
169 const unsigned int numberOfThreads = this->GetNumberOfThreads();
170 const unsigned int nBands = this->GetNumberOfBands();
171 const unsigned int nbImages = this->GetNumberOfInputImages();
173 itkDebugMacro(<<
"\nN threads: " << numberOfThreads <<
"\nN bands: " << nBands <<
"\nN images: " << nbImages);
175 m_InternalThreadResults.clear();
176 for (
unsigned int threadId = 0; threadId < numberOfThreads; threadId++)
180 m_InternalThreadResults.push_back(threadResult);
184 template <
class TInputImage,
class TOutputImage,
class TInternalValueType>
187 itkDebugMacro(<<
"Entering AllocateOutputs()");
198 template <
class TInputImage,
class TOutputImage,
class TInternalValueType>
201 itkDebugMacro(<<
"Entering Synthetize()");
203 const unsigned int nBands = Superclass::GetNumberOfBands();
204 const unsigned int nbImages = this->GetNumberOfInputImages();
208 for (
const auto& res : m_InternalThreadResults)
221 for (
unsigned int band = 0; band < nBands; band++)
226 RealMatrixType min(nbImages, nbImages, itk::NumericTraits<InputImageInternalPixelType>::max());
227 RealMatrixType max(nbImages, nbImages, itk::NumericTraits<InputImageInternalPixelType>::NonpositiveMin());
229 for (
unsigned int i = 0; i < nbImages; i++)
231 for (
unsigned int j = 0; j < nbImages; j++)
242 m_Area[i][j] = count;
245 if (minVal < min[i][j])
247 if (maxVal > max[i][j])
260 stdev[i][j] = vcl_sqrt(variance);
265 m_Means.push_back(
mean);
266 m_Stds.push_back(stdev);
267 m_ProdMeans.push_back(prodmean);
268 m_Mins.push_back(min);
269 m_Maxs.push_back(max);
273 this->GetMeansOutput()->Set(m_Means);
274 this->GetStdsOutput()->Set(m_Stds);
275 this->GetMeansOfProductsOutput()->Set(m_ProdMeans);
276 this->GetMinsOutput()->Set(m_Mins);
277 this->GetMaxsOutput()->Set(m_Maxs);
278 this->GetAreasOutput()->Set(m_Area);
284 template <
class TInputImage,
class TOutputImage,
class TInternalValueType>
286 itk::ThreadIdType threadId)
290 itkDebugMacro(<<
"Actually executing thread " << threadId <<
" in region " << outputRegionForThread);
293 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
296 const unsigned int nbOfInputImages = this->GetNumberOfInputImages();
299 const unsigned int nbOfUsedInputImages = Superclass::GetNumberOfUsedInputImages();
302 IteratorType outputIt(this->GetOutput(), outputRegionForThread);
305 typename std::vector<InputImageType*> currentImage;
306 typename std::vector<InterpolatorPointerType> interp;
307 Superclass::PrepareImageAccessors(currentImage, interp);
312 for (outputIt.GoToBegin(); !outputIt.IsAtEnd(); ++outputIt)
316 progress.CompletedPixel();
319 std::vector<unsigned int> overlapImagesIndices;
320 std::vector<InputImagePixelType> overlapPixelValue;
323 this->GetOutput()->TransformIndexToPhysicalPoint(outputIt.GetIndex(), geoPoint);
326 for (
unsigned int i = 0; i < nbOfUsedInputImages; i++)
332 if (interp[i]->IsInsideBuffer(geoPoint))
339 if (Superclass::IsPixelNotEmpty(interpolatedPixel))
341 overlapImagesIndices.push_back(Superclass::GetUsedInputImageIndice(i));
342 overlapPixelValue.push_back(interpolatedPixel);
351 unsigned int nbOfOverlappingPixels = overlapImagesIndices.size();
354 for (
unsigned int i = 0; i < nbOfOverlappingPixels; i++)
357 unsigned int imageIndex = overlapImagesIndices.at(i);
362 for (
unsigned int j = 0; j < nbOfOverlappingPixels; j++)
367 unsigned int otherImageIndex = overlapImagesIndices.at(j);
373 m_InternalThreadResults.at(threadId).Update(pixel, otherPixel, imageIndex * nbOfInputImages + otherImageIndex);