21 #ifndef __otbStreamingInnerProductVectorImageFilter_txx
22 #define __otbStreamingInnerProductVectorImageFilter_txx
27 #include "itkNumericTraits.h"
34 template<
class TInputImage>
46 typename ImageType::Pointer output1 =
static_cast<ImageType*
>(this->MakeOutput(0).GetPointer());
54 template<
class TInputImage>
65 return static_cast<itk::DataObject*
>(MatrixObjectType::New().GetPointer());
74 template<
class TInputImage>
82 template<
class TInputImage>
90 template<
class TInputImage>
95 Superclass::GenerateOutputInformation();
98 this->GetOutput()->CopyInformation(this->GetInput());
99 this->GetOutput()->SetLargestPossibleRegion(this->GetInput()->GetLargestPossibleRegion());
101 if (this->GetOutput()->GetRequestedRegion().GetNumberOfPixels() == 0)
103 this->GetOutput()->SetRequestedRegion(this->GetOutput()->GetLargestPossibleRegion());
108 template<
class TInputImage>
120 template<
class TInputImage>
125 TInputImage * inputPtr =
const_cast<TInputImage *
>(this->GetInput());
126 inputPtr->UpdateOutputInformation();
128 if (this->GetOutput()->GetRequestedRegion().GetNumberOfPixels() == 0)
130 this->GetOutput()->SetRequestedRegion(this->GetOutput()->GetLargestPossibleRegion());
133 unsigned int numberOfThreads = this->GetNumberOfThreads();
134 unsigned int numberOfTrainingImages = inputPtr->GetNumberOfComponentsPerPixel();
137 tempMatrix.set_size(numberOfTrainingImages, numberOfTrainingImages);
142 initMatrix.set_size(numberOfTrainingImages, numberOfTrainingImages);
144 this->GetInnerProductOutput()->Set(initMatrix);
148 template<
class TInputImage>
154 TInputImage * inputPtr =
const_cast<TInputImage *
>(this->GetInput());
155 unsigned int numberOfTrainingImages = inputPtr->GetNumberOfComponentsPerPixel();
156 unsigned int numberOfThreads = this->GetNumberOfThreads();
158 innerProduct.set_size(numberOfTrainingImages, numberOfTrainingImages);
159 innerProduct.fill(0);
162 for (
unsigned int thread = 0; thread < numberOfThreads; thread++)
164 innerProduct += m_ThreadInnerProduct[thread];
170 for (
unsigned int band_x = 0; band_x < (numberOfTrainingImages - 1); ++band_x)
172 for (
unsigned int band_y = band_x + 1; band_y < numberOfTrainingImages; ++band_y)
174 innerProduct[band_x][band_y] = innerProduct[band_y][band_x];
178 if ((numberOfTrainingImages - 1) != 0)
180 innerProduct /= (numberOfTrainingImages - 1);
184 innerProduct.fill(0);
188 this->GetInnerProductOutput()->Set(innerProduct);
191 template<
class TInputImage>
202 unsigned int numberOfTrainingImages = inputPtr->GetNumberOfComponentsPerPixel();
205 if (m_CenterData ==
true)
213 for (
unsigned int i = 0; i < vectorValue.GetSize(); ++i)
215 mean +=
static_cast<double>(vectorValue[i]);
217 mean /=
static_cast<double>(vectorValue.GetSize());
220 for (
unsigned int band_x = 0; band_x < numberOfTrainingImages; ++band_x)
222 for (
unsigned int band_y = 0; band_y <= band_x; ++band_y)
224 m_ThreadInnerProduct[threadId][band_x][band_y] +=
225 (
static_cast<double>(vectorValue[band_x]) - mean) * (
static_cast<double>(vectorValue[band_y]) - mean);
229 progress.CompletedPixel();
240 for (
unsigned int band_x = 0; band_x < numberOfTrainingImages; ++band_x)
242 for (
unsigned int band_y = 0; band_y <= band_x; ++band_y)
244 m_ThreadInnerProduct[threadId][band_x][band_y] +=
245 (
static_cast<double>(vectorValue[band_x])) * (
static_cast<double>(vectorValue[band_y]));
249 progress.CompletedPixel();
254 template <
class TImage>
259 Superclass::PrintSelf(os, indent);
260 os << indent <<
"m_CenterData: " << m_CenterData << std::endl;
261 os << indent <<
"InnerProduct: " << this->GetInnerProductOutput()->Get() << std::endl;