21 #ifndef __otbVCAImageFilter_txx
22 #define __otbVCAImageFilter_txx
29 template<
class TImage>
31 : m_NumberOfEndmembers(0)
35 template<
class TImage>
40 template<
class TImage>
44 Superclass::GenerateOutputInformation();
47 typename VectorImageType::ConstPointer inputPtr = this->GetInput();
48 typename VectorImageType::Pointer outputPtr = this->GetOutput();
50 if ( !inputPtr || !outputPtr )
55 const unsigned int numberOfBands = inputPtr->GetNumberOfComponentsPerPixel();
61 outputSize[0] = m_NumberOfEndmembers;
63 outputRegion.SetIndex(outputOrigin);
64 outputRegion.SetSize(outputSize);
66 outputPtr->SetLargestPossibleRegion( outputRegion );
67 outputPtr->SetNumberOfComponentsPerPixel( numberOfBands );
70 template<
class TImage>
76 const unsigned int nbBands = this->GetInput()->GetNumberOfComponentsPerPixel();
81 StreamingStatisticsVectorImageFilterType::New();
83 statsInput->SetInput(input);
84 statsInput->SetEnableMinMax(
false);
93 vnl_svd<PrecisionType> svd(R);
99 typename NormalizeFilterType::Pointer normalize = NormalizeFilterType::New();
100 normalize->SetInput(input);
101 normalize->SetMean(statsInput->GetMean());
102 normalize->SetUseMean(
true);
103 normalize->SetUseStdDev(
false);
106 mulUd->MatrixByVectorOn();
107 mulUd->SetInput(normalize->GetOutput());
108 mulUd->SetMatrix(Udt);
109 mulUd->UpdateOutputInformation();
112 StreamingStatisticsVectorImageFilterType::New();
114 transformedStats->SetInput(mulUd->GetOutput());
115 transformedStats->SetEnableMinMax(
false);
116 transformedStats->Update();
118 double P_R = nbBands * statsInput->GetComponentCorrelation();
119 double P_Rp = m_NumberOfEndmembers * transformedStats->GetComponentCorrelation()
120 + statsInput->GetMean().GetSquaredNorm();
122 SNR = vcl_abs(10*vcl_log10( (P_Rp - (m_NumberOfEndmembers/nbBands)*P_R) / (P_R - P_Rp) ));
125 SNRth = 15.0 + 10.0 * vcl_log( static_cast<double>(m_NumberOfEndmembers) ) + 8.0;
127 typename VectorImageType::Pointer Xd;
128 typename VectorImageType::Pointer Y;
130 std::vector<itk::ProcessObject::Pointer> refHolder;
132 typename NormalizeFilterType::Pointer normalize = NormalizeFilterType::New();
136 otbMsgDevMacro(
"Using projective projection for dimensionnality reduction" )
143 vnl_svd<PrecisionType> svd(R);
145 Ud = U.get_n_columns(0, m_NumberOfEndmembers);
151 mulUd->MatrixByVectorOn();
152 mulUd->SetInput(this->GetInput());
153 mulUd->SetMatrix(UdT);
154 mulUd->UpdateOutputInformation();
157 Xd = mulUd->GetOutput();
162 statsXd = StreamingStatisticsVectorImageFilterType::New();
163 statsXd->SetEnableSecondOrderStats(
false);
164 statsXd->SetInput(Xd);
167 typename VectorImageType::PixelType Xdmean = statsXd->GetMean();
175 proj->SetProjectionDirection(Xdmean);
178 Xd = proj->GetOutput();
186 normalize->SetInput(input);
187 normalize->SetMean(statsInput->GetMean());
188 normalize->SetUseMean(
true);
189 normalize->SetUseStdDev(
false);
195 vnl_svd<PrecisionType> svd(R);
197 Ud = U.get_n_columns(0, m_NumberOfEndmembers - 1);
201 mulUd->MatrixByVectorOn();
202 mulUd->SetInput(normalize->GetOutput());
203 mulUd->SetMatrix(UdT);
204 mulUd->UpdateOutputInformation();
207 Xd = mulUd->GetOutput();
210 normComputer->SetInput(Xd);
213 maxNormComputer->SetInput(normComputer->GetOutput());
214 maxNormComputer->Update();
219 concat->SetInput(Xd);
220 concat->SetScalarValue(maxNorm);
223 Y = concat->GetOutput();
224 Y->UpdateOutputInformation();
234 A(m_NumberOfEndmembers - 1, 0) = 1;
237 for (
unsigned int i = 0; i < m_NumberOfEndmembers; ++i)
245 for (
unsigned int j = 0; j < w.size(); ++j)
247 w(j) = randomGen->GetVariateWithOpenRange();
251 otbMsgDevMacro(
"f = ((I - A*pinv(A))*w) /(norm(I - A*pinv(A))*w))" )
253 tmpMat.set_identity();
255 vnl_svd<PrecisionType> Asvd(A);
256 tmpMat -= A * Asvd.inverse();
267 typename VectorImageType::PixelType fV(f.data_block(), f.size());
268 dotfY->SetVector(
typename VectorImageType::PixelType(fV));
274 absVFilter->SetInput(v);
279 maxAbs->SetInput(absVFilter->GetOutput());
284 IndexType maxIdx = maxAbs->GetMaximumIndex();
291 region.SetIndex( maxIdx );
294 region.SetSize(size);
295 Y->SetRequestedRegion(region);
301 typename VectorImageType::PixelType e = Y->GetPixel(maxIdx);
303 A.set_column(i, e.GetDataPointer());
313 Xd->SetRequestedRegion(region);
315 typename VectorImageType::PixelType xd = Xd->GetPixel(maxIdx);
323 Xd->SetRequestedRegion(region);
325 typename VectorImageType::PixelType xd = Xd->GetPixel(maxIdx);
339 typename VectorImageType::Pointer output = this->GetOutput();
340 output->SetRegions(output->GetLargestPossibleRegion());
346 for (it.GoToBegin(), i = 0; !it.
IsAtEnd(); ++it, ++i)
349 typename VectorImageType::PixelType pixel(input->GetNumberOfComponentsPerPixel());
350 for (
unsigned int j = 0; j < e.size(); ++j)
361 template<
class TImage>
364 Superclass::PrintSelf( os, indent );