Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Main Repositories
otb
Commits
8465c06d
Commit
8465c06d
authored
Apr 07, 2020
by
Cédric Traizet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENH: code review
parent
439cb25e
Pipeline
#4133
failed with stages
in 4 minutes and 37 seconds
Changes
4
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
31 deletions
+17
-31
Modules/Applications/AppHyperspectral/app/otbSpectralAngleClassification.cxx
...s/AppHyperspectral/app/otbSpectralAngleClassification.cxx
+3
-13
Modules/Filtering/ImageManipulation/include/otbBinarySpectralAngleFunctor.h
...ImageManipulation/include/otbBinarySpectralAngleFunctor.h
+3
-2
Modules/Filtering/ImageManipulation/include/otbSpectralAngleFunctor.h
...ering/ImageManipulation/include/otbSpectralAngleFunctor.h
+8
-14
Modules/Filtering/ImageManipulation/include/otbSpectralInformationDivergenceFunctor.h
...ulation/include/otbSpectralInformationDivergenceFunctor.h
+3
-2
No files found.
Modules/Applications/AppHyperspectral/app/otbSpectralAngleClassification.cxx
View file @
8465c06d
...
...
@@ -192,21 +192,11 @@ private:
:
std
::
numeric_limits
<
ValueType
>::
max
();
auto
bv
=
GetParameterInt
(
"bv"
);
// This lambda return the index of the minimum value in a pixel, values above threshold are
not
classified.
// This lambda return the index of the minimum value in a pixel, values above threshold are classified
as background values
.
auto
minIndexLambda
=
[
threshold
,
bv
](
PixelType
const
&
pixel
)
{
auto
min
=
threshold
;
int
res
=
bv
;
for
(
unsigned
int
i
=
0
;
i
<
pixel
.
Size
();
i
++
)
{
if
(
pixel
[
i
]
<
min
)
{
min
=
pixel
[
i
];
res
=
i
+
1
;
}
}
return
res
;
auto
minElem
=
std
::
min_element
(
&
pixel
[
0
],
&
pixel
[
pixel
.
Size
()]);
return
static_cast
<
int
>
(
*
minElem
<
threshold
?
std
::
distance
(
&
pixel
[
0
],
minElem
)
+
1
:
bv
);
};
auto
classificationFilter
=
NewFunctorFilter
(
minIndexLambda
);
...
...
Modules/Filtering/ImageManipulation/include/otbBinarySpectralAngleFunctor.h
View file @
8465c06d
...
...
@@ -49,12 +49,13 @@ public:
virtual
~
BinarySpectralAngleFunctor
()
=
default
;
// Binary operator
inline
TOutputValue
operator
()(
const
TInput1
&
in1
,
const
TInput2
&
in2
)
const
TOutputValue
operator
()(
const
TInput1
&
in1
,
const
TInput2
&
in2
)
const
{
// Compute norms.
auto
in1Norm
=
0
;
auto
in2Norm
=
0
;
for
(
unsigned
int
i
=
0
;
i
<
std
::
min
(
in1
.
Size
(),
in2
.
Size
());
++
i
)
auto
nbIter
=
std
::
min
(
in1
.
Size
(),
in2
.
Size
());
for
(
unsigned
int
i
=
0
;
i
<
nbIter
;
++
i
)
{
in1Norm
+=
in1
[
i
]
*
in1
[
i
];
in2Norm
+=
in2
[
i
]
*
in2
[
i
];
...
...
Modules/Filtering/ImageManipulation/include/otbSpectralAngleFunctor.h
View file @
8465c06d
...
...
@@ -41,12 +41,7 @@ template <class TInput, class TReference, class TOutput>
TOutput
ComputeSpectralAngle
(
TInput
const
&
input
,
typename
TInput
::
ValueType
const
&
inputNorm
,
TReference
const
&
reference
,
typename
TReference
::
ValueType
refNorm
)
{
// Compute scalar product.
double
scalarProduct
=
0.0
;
for
(
unsigned
int
i
=
0
;
i
<
std
::
min
(
input
.
Size
(),
reference
.
Size
());
++
i
)
{
scalarProduct
+=
input
[
i
]
*
reference
[
i
];
}
double
scalarProduct
=
std
::
inner_product
(
&
input
[
0
],
&
input
[
input
.
Size
()],
&
reference
[
0
],
0.
);
auto
normProd
=
inputNorm
*
refNorm
;
if
((
normProd
==
0.0
)
||
(
scalarProduct
/
normProd
>
1
))
{
...
...
@@ -75,7 +70,7 @@ public:
m_ReferencePixel
.
Fill
(
1
);
}
virtual
~
SpectralAngleFunctor
()
=
default
;
~
SpectralAngleFunctor
()
=
default
;
// Binary operator
inline
TOutputValue
operator
()(
TInput
const
&
inPix
)
const
...
...
@@ -114,8 +109,7 @@ public:
// Binary operator
inline
TOutput
operator
()(
const
TInput
&
inPix
)
const
{
TOutput
res
;
res
.
SetSize
(
m_ReferencePixels
.
size
());
TOutput
res
(
m_ReferencePixels
.
size
());
auto
inputNorm
=
inPix
.
GetNorm
();
...
...
@@ -133,18 +127,18 @@ public:
return
m_ReferencePixels
.
size
();
}
void
SetReferencePixels
(
std
::
vector
<
TReference
>
const
&
ref
)
void
SetReferencePixels
(
std
::
vector
<
TReference
>
ref
)
{
m_ReferencePixels
=
ref
;
m_ReferencePixels
=
std
::
move
(
ref
)
;
m_ReferenceNorm
.
clear
();
// Precompute the norm of reference pixels
for
(
auto
const
&
pix
:
ref
)
for
(
auto
const
&
pix
el
:
m_ReferencePixels
)
{
m_ReferenceNorm
.
push_back
(
pix
.
GetNorm
());
m_ReferenceNorm
.
push_back
(
pix
el
.
GetNorm
());
}
}
std
::
vector
<
TReference
>
GetReferencePixels
()
const
std
::
vector
<
TReference
>
const
&
GetReferencePixels
()
const
{
return
m_ReferencePixels
;
}
...
...
Modules/Filtering/ImageManipulation/include/otbSpectralInformationDivergenceFunctor.h
View file @
8465c06d
...
...
@@ -89,7 +89,7 @@ private:
// Input pixel should be non negative (e.g. reflectance, radiance)
if
(
input
[
i
]
<=
0
)
{
throw
std
::
domain
_error
(
"Input pixel of the spectral information divergence algorithm should be strictly positive."
);
throw
std
::
runtime
_error
(
"Input pixel
s
of the spectral information divergence algorithm should be strictly positive."
);
}
sum
+=
input
[
i
];
}
...
...
@@ -107,7 +107,8 @@ private:
OutputValueType
sid
=
0.0
;
for
(
unsigned
int
i
=
0
;
i
<
p
.
Size
();
i
++
)
{
sid
+=
p
[
i
]
*
std
::
log
(
p
[
i
]
/
q
[
i
])
+
q
[
i
]
*
std
::
log
(
q
[
i
]
/
p
[
i
]);
// Compute SID : p[i] * std::log(p[i]/q[i]) + q[i] * std::log(q[i]/p[i]);
sid
+=
(
p
[
i
]
-
q
[
i
])
*
std
::
log
(
p
[
i
]
/
q
[
i
]);
}
return
sid
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment