Skip to content
Snippets Groups Projects
Commit 89fc81cc authored by Cédric Traizet's avatar Cédric Traizet
Browse files

ENH: add parameter to DimensionalityReduction to output pca eigenvalues

parent 5d9e729e
No related branches found
No related tags found
No related merge requests found
...@@ -127,6 +127,10 @@ private: ...@@ -127,6 +127,10 @@ private:
AddChoice("method.pca", "PCA"); AddChoice("method.pca", "PCA");
SetParameterDescription("method.pca", "Principal Component Analysis."); SetParameterDescription("method.pca", "Principal Component Analysis.");
AddParameter(ParameterType_OutputFilename, "method.pca.outeigenvalues", "Output file containing eigenvalues (txt format)");
SetParameterDescription("method.pca.outeigenvalues", "Output file containing eigenvalues (txt format).");
MandatoryOff("method.pca.outeigenvalues");
AddChoice("method.napca", "NA-PCA"); AddChoice("method.napca", "NA-PCA");
SetParameterDescription("method.napca", "Noise Adjusted Principal Component Analysis."); SetParameterDescription("method.napca", "Noise Adjusted Principal Component Analysis.");
AddParameter(ParameterType_Int, "method.napca.radiusx", "Set the x radius of the sliding window"); AddParameter(ParameterType_Int, "method.napca.radiusx", "Set the x radius of the sliding window");
...@@ -138,6 +142,7 @@ private: ...@@ -138,6 +142,7 @@ private:
AddChoice("method.maf", "MAF"); AddChoice("method.maf", "MAF");
SetParameterDescription("method.maf", "Maximum Autocorrelation Factor."); SetParameterDescription("method.maf", "Maximum Autocorrelation Factor.");
AddChoice("method.ica", "ICA"); AddChoice("method.ica", "ICA");
SetParameterDescription("method.ica", "Independent Component Analysis using a stabilized fixed point FastICA algorithm."); SetParameterDescription("method.ica", "Independent Component Analysis using a stabilized fixed point FastICA algorithm.");
AddParameter(ParameterType_Int, "method.ica.iter", "number of iterations"); AddParameter(ParameterType_Int, "method.ica.iter", "number of iterations");
...@@ -258,6 +263,19 @@ private: ...@@ -258,6 +263,19 @@ private:
filter->SetUseNormalization(normalize); filter->SetUseNormalization(normalize);
m_ForwardFilter->GetOutput()->UpdateOutputInformation(); m_ForwardFilter->GetOutput()->UpdateOutputInformation();
//Write transformation matrix
std::ofstream outFile;
outFile.open(this->GetParameterString("method.pca.outeigenvalues"));
if (outFile.is_open())
{
outFile << std::fixed;
outFile.precision(10);
outFile << filter->GetEigenValues() << std::endl;;
outFile.close();
}
if (invTransform) if (invTransform)
{ {
invFilter->SetInput(m_ForwardFilter->GetOutput()); invFilter->SetInput(m_ForwardFilter->GetOutput());
...@@ -276,6 +294,7 @@ private: ...@@ -276,6 +294,7 @@ private:
} }
m_TransformationMatrix = filter->GetTransformationMatrix(); m_TransformationMatrix = filter->GetTransformationMatrix();
otbAppLogINFO("PCA transform has been computed."); otbAppLogINFO("PCA transform has been computed.");
break; break;
} }
...@@ -443,11 +462,14 @@ private: ...@@ -443,11 +462,14 @@ private:
//Write transformation matrix //Write transformation matrix
std::ofstream outFile; std::ofstream outFile;
outFile.open(this->GetParameterString("outmatrix")); outFile.open(this->GetParameterString("outmatrix"));
outFile << std::fixed; if (outFile.is_open())
outFile.precision(10); {
outFile << std::fixed;
outFile.precision(10);
outFile << m_TransformationMatrix; outFile << m_TransformationMatrix;
outFile.close(); outFile.close();
}
} }
} }
......
...@@ -394,6 +394,10 @@ PCAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation > ...@@ -394,6 +394,10 @@ PCAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation >
for ( unsigned int i = 0; i < vectValP.size(); ++i ) for ( unsigned int i = 0; i < vectValP.size(); ++i )
valP(i, i) = vectValP[i]; valP(i, i) = vectValP[i];
m_EigenValues.SetSize( m_NumberOfPrincipalComponentsRequired );
for ( unsigned int i = 0; i < m_NumberOfPrincipalComponentsRequired; ++i )
m_EigenValues[i] = static_cast< RealType >( valP(i, i) );
/* We used normalized PCA */ /* We used normalized PCA */
for ( unsigned int i = 0; i < valP.rows(); ++i ) for ( unsigned int i = 0; i < valP.rows(); ++i )
{ {
...@@ -421,10 +425,6 @@ PCAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation > ...@@ -421,10 +425,6 @@ PCAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation >
else else
m_TransformationMatrix = transf; m_TransformationMatrix = transf;
m_EigenValues.SetSize( m_NumberOfPrincipalComponentsRequired );
for ( unsigned int i = 0; i < m_NumberOfPrincipalComponentsRequired; ++i )
m_EigenValues[i] = static_cast< RealType >( valP(i, i) );
#endif #endif
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment