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
Container Registry
Model registry
Operate
Environments
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
Sébastien Peillet
otb
Commits
e1994ace
Commit
e1994ace
authored
11 years ago
by
Manuel Grizonnet
Browse files
Options
Downloads
Patches
Plain Diff
ENH: add new parameter to save transformation matrix in a csv file
parent
66a0b3be
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Applications/FeatureExtraction/otbDimensionalityReduction.cxx
+57
-6
57 additions, 6 deletions
...ications/FeatureExtraction/otbDimensionalityReduction.cxx
with
57 additions
and
6 deletions
Applications/FeatureExtraction/otbDimensionalityReduction.cxx
+
57
−
6
View file @
e1994ace
...
...
@@ -72,7 +72,9 @@ public:
typedef
otb
::
FastICAImageFilter
<
FloatVectorImageType
,
FloatVectorImageType
,
otb
::
Transform
::
INVERSE
>
ICAInverseFilterType
;
//typedef otb::StreamingStatisticsVectorImageFilter<FloatVectorImageType> StreamingStatisticsVectorImageFilterType;
typedef
otb
::
StreamingStatisticsVectorImageFilter
<
FloatVectorImageType
>
StreamingStatisticsVectorImageFilterType
;
typedef
StreamingStatisticsVectorImageFilterType
::
MatrixObjectType
::
ComponentType
MatrixType
;
//typedef otb::VirtualDimensionality<double> VDFilterType;
...
...
@@ -167,6 +169,10 @@ private:
SetParameterDescription
(
"normalize"
,
"center AND reduce data before Dimensionality reduction."
);
MandatoryOff
(
"normalize"
);
AddParameter
(
ParameterType_OutputFilename
,
"outmatrix"
,
"Transformation matrix output"
);
SetParameterDescription
(
"outmatrix"
,
"Filename to store the transformation matrix (csv format)"
);
MandatoryOff
(
"outmatrix"
);
// Doc example parameter settings
SetDocExampleParameterValue
(
"in"
,
"cupriteSubHsi.tif"
);
SetDocExampleParameterValue
(
"out"
,
"FilterOutput.tif"
);
...
...
@@ -191,17 +197,19 @@ private:
// PCA Algorithm
case
0
:
{
otbAppLogDEBUG
(
<<
"PCA Algorithm "
);
PCAForwardFilterType
::
Pointer
filter
=
PCAForwardFilterType
::
New
();
m_ForwardFilter
=
filter
;
PCAInverseFilterType
::
Pointer
invFilter
=
PCAInverseFilterType
::
New
();
m_InverseFilter
=
invFilter
;
filter
->
SetInput
(
GetParameterFloatVectorImage
(
"in"
));
filter
->
SetNumberOfPrincipalComponentsRequired
(
nbComp
);
filter
->
SetUseNormalization
(
normalize
);
m_ForwardFilter
->
Update
();
if
(
invTransform
)
{
invFilter
->
SetInput
(
m_ForwardFilter
->
GetOutput
());
...
...
@@ -214,8 +222,11 @@ private:
}
invFilter
->
SetTransformationMatrix
(
filter
->
GetTransformationMatrix
());
m_TransformationMatrix
=
invFilter
->
GetTransformationMatrix
();
}
m_TransformationMatrix
=
filter
->
GetTransformationMatrix
();
break
;
}
case
1
:
...
...
@@ -235,6 +246,7 @@ private:
NAPCAInverseFilterType
::
Pointer
invFilter
=
NAPCAInverseFilterType
::
New
();
m_InverseFilter
=
invFilter
;
filter
->
SetInput
(
GetParameterFloatVectorImage
(
"in"
));
filter
->
SetNumberOfPrincipalComponentsRequired
(
nbComp
);
filter
->
SetUseNormalization
(
normalize
);
...
...
@@ -251,8 +263,10 @@ private:
}
invFilter
->
SetTransformationMatrix
(
filter
->
GetTransformationMatrix
());
m_TransformationMatrix
=
invFilter
->
GetTransformationMatrix
();
}
m_TransformationMatrix
=
filter
->
GetTransformationMatrix
();
break
;
}
...
...
@@ -270,7 +284,7 @@ private:
}
case
3
:
{
otbAppLogDEBUG
(
<<
"ICA Algorithm "
);
otbAppLogDEBUG
(
<<
"
Fast
ICA Algorithm "
);
unsigned
int
nbIterations
=
static_cast
<
unsigned
int
>
(
GetParameterInt
(
"method.ica.iter"
));
double
mu
=
static_cast
<
double
>
(
GetParameterFloat
(
"method.ica.mu"
));
...
...
@@ -285,6 +299,7 @@ private:
filter
->
SetNumberOfIterations
(
nbIterations
);
filter
->
SetMu
(
mu
);
m_ForwardFilter
->
Update
();
if
(
invTransform
)
{
otbAppLogDEBUG
(
<<
"Compute Inverse Transform"
);
...
...
@@ -298,6 +313,9 @@ private:
invFilter
->
SetPCATransformationMatrix
(
filter
->
GetPCATransformationMatrix
());
invFilter
->
SetTransformationMatrix
(
filter
->
GetTransformationMatrix
());
}
m_TransformationMatrix
=
filter
->
GetTransformationMatrix
();
break
;
}
/* case 4:
...
...
@@ -325,6 +343,36 @@ private:
else
SetParameterOutputImage
(
"outinv"
,
m_InverseFilter
->
GetOutput
());
}
//Write transformation matrix
if
(
this
->
GetParameterString
(
"outmatrix"
).
c_str
())
{
if
(
GetParameterInt
(
"method"
)
==
2
)
//MAF or VD
{
otbAppLogWARNING
(
<<
"No transformation matrix available for MAF."
);
}
else
{
//Write transformation matrix
std
::
ofstream
outFile
;
outFile
.
open
(
this
->
GetParameterString
(
"outmatrix"
).
c_str
());
outFile
<<
std
::
fixed
;
outFile
.
precision
(
10
);
outFile
<<
m_TransformationMatrix
;
// if (invTransform)
// {
// outFile << m_InverseFilter->GetTransformationMatrix();
// }
// else
// {
// outFile << m_ForwardFilter->GetTransformationMatrix();
// }
//outFile << std::endl;
outFile
.
close
();
}
}
if
(
!
rescale
)
{
SetParameterOutputImage
(
"out"
,
m_ForwardFilter
->
GetOutput
());
...
...
@@ -364,12 +412,15 @@ private:
SetParameterOutputImage
(
"out"
,
m_RescaleFilter
->
GetOutput
());
}
}
MinMaxFilterType
::
Pointer
m_MinMaxFilter
;
RescaleImageFilterType
::
Pointer
m_RescaleFilter
;
DimensionalityReductionFilter
::
Pointer
m_ForwardFilter
;
DimensionalityReductionFilter
::
Pointer
m_InverseFilter
;
DimensionalityReductionFilter
::
Pointer
m_ForwardFilter
;
DimensionalityReductionFilter
::
Pointer
m_InverseFilter
;
MatrixType
m_TransformationMatrix
;
};
}
...
...
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