Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
otb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Youssefi
otb
Commits
2554c439
Commit
2554c439
authored
14 years ago
by
Grégoire Mercier
Browse files
Options
Downloads
Patches
Plain Diff
REFAC: use svd in PCA
parent
adcabf27
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Code/Hyperspectral/otbPCAImageFilter.h
+3
-1
3 additions, 1 deletion
Code/Hyperspectral/otbPCAImageFilter.h
Code/Hyperspectral/otbPCAImageFilter.txx
+44
-3
44 additions, 3 deletions
Code/Hyperspectral/otbPCAImageFilter.txx
with
47 additions
and
4 deletions
Code/Hyperspectral/otbPCAImageFilter.h
+
3
−
1
View file @
2554c439
...
...
@@ -78,6 +78,8 @@ public:
typedef
typename
CovarianceEstimatorFilterType
::
RealPixelType
VectorType
;
typedef
typename
CovarianceEstimatorFilterType
::
MatrixObjectType
MatrixObjectType
;
typedef
typename
MatrixObjectType
::
ComponentType
MatrixType
;
typedef
typename
MatrixType
::
InternalMatrixType
InternalMatrixType
;
typedef
typename
InternalMatrixType
::
element_type
MatrixElementType
;
typedef
MatrixMultiplyImageFilter
<
TInputImage
,
TOutputImage
,
RealType
>
TransformFilterType
;
typedef
typename
TransformFilterType
::
Pointer
TransformFilterPointerType
;
...
...
@@ -180,7 +182,7 @@ protected:
virtual
void
ForwardGenerateData
();
virtual
void
ReverseGenerateData
();
void
Ge
t
TransformationMatrix
FromCovarianceMatrix
();
void
Ge
nerate
TransformationMatrix
();
/** Internal attributes */
unsigned
int
m_NumberOfPrincipalComponentsRequired
;
...
...
This diff is collapsed.
Click to expand it.
Code/Hyperspectral/otbPCAImageFilter.txx
+
44
−
3
View file @
2554c439
...
...
@@ -188,7 +188,7 @@ PCAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation >
m_Transformer->SetInput( inputImgPtr );
}
Ge
t
TransformationMatrix
FromCovarianceMatrix
();
Ge
nerate
TransformationMatrix();
}
else if ( !m_IsTransformationMatrixForward )
{
...
...
@@ -225,7 +225,7 @@ PCAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation >
ITK_LOCATION );
}
Ge
t
TransformationMatrix
FromCovarianceMatrix
();
Ge
nerate
TransformationMatrix();
m_TransformationMatrix = m_TransformationMatrix.GetTranspose();
}
else if ( m_IsTransformationMatrixForward )
...
...
@@ -291,8 +291,13 @@ template < class TInputImage, class TOutputImage,
Transform::TransformDirection TDirectionOfTransformation >
void
PCAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation >
::Ge
t
TransformationMatrix
FromCovarianceMatrix
()
::Ge
nerate
TransformationMatrix ()
{
#if 0
/*
* Old stuff but did work !
*/
MatrixType Id ( m_CovarianceMatrix );
Id.SetIdentity();
...
...
@@ -331,6 +336,42 @@ PCAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation >
m_EigenValues.SetSize( m_NumberOfPrincipalComponentsRequired );
for ( unsigned int i = 0; i < m_NumberOfPrincipalComponentsRequired; i++ )
m_EigenValues[i] = static_cast< RealType >( valP[i] );
#else
vnl_svd< MatrixElementType > solver ( m_CovarianceMatrix.GetVnlMatrix() );
InternalMatrixType transf = solver.U();
InternalMatrixType valP = solver.W();
/* We used normalized PCA */
for ( unsigned int i = 0; i < valP.rows(); i++ )
{
if ( valP(i,i) == 0. )
valP(i,i) = 1. / vcl_sqrt( vcl_abs( valP(i,i) ) );
else
otbMsgDebugMacro( << "ValP(" << i << ") null : " << valP(i,i) );
//throw itk::ExceptionObject( __FILE__, __LINE__,
// "Null Eigen value !!", ITK_LOCATION );
}
transf = valP * transf.transpose();
if ( m_NumberOfPrincipalComponentsRequired
!= this->GetInput()->GetNumberOfComponentsPerPixel() )
m_TransformationMatrix = transf.get_n_rows( 0, m_NumberOfPrincipalComponentsRequired );
else
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) );
std::cerr << "Matrice de transformation \n";
std::cerr << m_TransformationMatrix << "\n";
std::cerr << "Vecteurs propres\n";
std::cerr << m_EigenValues << "\n";
std::cerr << "Matrice W\n" << solver.W();
#endif
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment