Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Lozac'h Loic
AgriSoilMoisture
Commits
8f51af62
Commit
8f51af62
authored
Jan 14, 2021
by
Lozac'h Loic
Browse files
ADD gestion pente
parent
80cbe96f
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/otbInvertSARModel.cxx
View file @
8f51af62
...
...
@@ -6,6 +6,7 @@
#include "otbTensorflowSource.h"
// Stats
#include "otbStreamingStatisticsMapFromLabelImageFilter.h"
#include "otbStreamingStatisticsMapFromLabelImageFilter2.h"
// Tensorflow stuff
#include "tensorflow/core/public/session.h"
...
...
@@ -47,7 +48,7 @@ public:
typedef
TensorflowSource
<
FloatVectorImageType
>
TFSourceType
;
/** Statistics */
typedef
otb
::
StreamingStatisticsMapFromLabelImageFilter
<
FloatVectorImageType
,
UInt32ImageType
>
StatsFilterType
;
typedef
otb
::
StreamingStatisticsMapFromLabelImageFilter
2
<
FloatVectorImageType
,
UInt32ImageType
>
StatsFilterType
;
typedef
itk
::
ImageRegionIterator
<
FloatVectorImageType
>
IteratorType
;
typedef
itk
::
ImageRegionConstIterator
<
FloatVectorImageType
>
ConstIteratorType
;
...
...
@@ -173,7 +174,6 @@ private:
}
else
{
m_ImageList
->
PushBack
(
m_SarVHFunctorFilter
->
GetOutput
());
}
m_ImageList
->
PushBack
(
GetParameterFloatVectorImage
(
"inlabels"
));
m_ImageSource
.
Set
(
m_ImageList
);
// Compute stats
...
...
@@ -194,7 +194,8 @@ private:
//get count for each label
StatsFilterType
::
LabelPopulationMapType
countValues
=
m_StatsFilter
->
GetLabelPopulationMap
();
StatsFilterType
::
VectorValidPixelsRatioMapType
validRatioMap
=
m_StatsFilter
->
GetValidPixelsRatioMap
();
// for (const auto& entry: meanValues)
// std::cout << "Id:" << entry.first << ", value=" << entry.second << std::endl;
...
...
@@ -203,9 +204,8 @@ private:
for
(
auto
&
entry
:
meanValues
)
{
float
ratiolabel
=
countValues
.
at
(
entry
.
first
)[
2
]
/
countValues
.
at
(
entry
.
first
)[
3
];
otbAppLogINFO
(
"Debug ratio = "
<<
(
ratiolabel
));
if
(
ratiolabel
<
0.5
or
countValues
.
at
(
entry
.
first
)[
2
]
<
20
or
entry
.
second
[
0
]
==
0
or
entry
.
second
[
1
]
==
0
or
entry
.
second
[
2
]
==
0
double
nbsarpix
=
countValues
.
at
(
entry
.
first
)
*
validRatioMap
.
at
(
entry
.
first
)[
2
];
if
(
validRatioMap
.
at
(
entry
.
first
)[
2
]
<
0.5
or
nbsarpix
<
20
or
entry
.
second
[
0
]
==
0
or
entry
.
second
[
1
]
==
0
or
entry
.
second
[
2
]
==
0
or
isnan
(
entry
.
second
[
0
])
or
isnan
(
entry
.
second
[
1
])
or
isnan
(
entry
.
second
[
2
])){
wronglabels
.
push_back
(
entry
.
first
);
}
else
{
...
...
include/otbStreamingStatisticsMapFromLabelImageFilter2.h
0 → 100644
View file @
8f51af62
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: otbStreamingStatisticsMapFromLabelImageFilter2.h
* Author: otbuser
*
* Created on January 14, 2021, 12:54 AM
*/
#ifndef OTBSTREAMINGSTATISTICSMAPFROMLABELIMAGEFILTER2_H
#define OTBSTREAMINGSTATISTICSMAPFROMLABELIMAGEFILTER2_H
#include "otbPersistentImageFilter.h"
#include "itkNumericTraits.h"
#include "itkArray.h"
#include "itkSimpleDataObjectDecorator.h"
#include "otbPersistentFilterStreamingDecorator.h"
#include <unordered_map>
namespace
otb
{
template
<
class
TInputVectorImage
,
class
TLabelImage
>
class
ITK_EXPORT
PersistentStreamingStatisticsMapFromLabelImageFilter2
:
public
PersistentStreamingStatisticsMapFromLabelImageFilter
<
TInputVectorImage
,
TInputVectorImage
>
{
public:
/** Standard Self typedef */
typedef
PersistentStreamingStatisticsMapFromLabelImageFilter2
Self
;
typedef
PersistentStreamingStatisticsMapFromLabelImageFilter
<
TInputVectorImage
,
TInputVectorImage
>
Superclass
;
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
typedef
itk
::
SmartPointer
<
const
Self
>
ConstPointer
;
/** Method for creation through the object factory. */
itkNewMacro
(
Self
);
/** Runtime information support. */
itkTypeMacro
(
PersistentStreamingStatisticsMapFromLabelImageFilter2
,
PersistentStreamingStatisticsMapFromLabelImageFilter
);
typedef
typename
LabelImageType
::
PixelType
LabelPixelType
;
typedef
itk
::
VariableLengthVector
<
double
>
RealVectorValidPixelsRatioType
;
typedef
std
::
unordered_map
<
LabelPixelType
,
RealVectorValidPixelsRatioType
>
VectorValidPixelsRatioMapType
;
/** Return the ratio between valid pixels for each band and pixels in each label */
VectorValidPixelsRatioMapType
GetValidPixelsRatioMap
()
const
;
void
Synthetize
(
void
)
override
;
private:
VectorValidPixelsRatioMapType
m_CountPixel
;
};
template
<
class
TInputVectorImage
,
class
TLabelImage
>
class
ITK_EXPORT
StreamingStatisticsMapFromLabelImageFilter2
:
public
PersistentFilterStreamingDecorator
<
PersistentStreamingStatisticsMapFromLabelImageFilter2
<
TInputVectorImage
,
TLabelImage
>>
{
public:
/** Standard Self typedef */
typedef
StreamingStatisticsMapFromLabelImageFilter2
Self
;
typedef
PersistentFilterStreamingDecorator
<
PersistentStreamingStatisticsMapFromLabelImageFilter2
<
TInputVectorImage
,
TLabelImage
>>
Superclass
;
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
typedef
itk
::
SmartPointer
<
const
Self
>
ConstPointer
;
/** Type macro */
itkNewMacro
(
Self
);
/** Creation through object factory macro */
itkTypeMacro
(
StreamingStatisticsMapFromLabelImageFilter2
,
StreamingStatisticsMapFromLabelImageFilter
);
typedef
typename
Superclass
::
FilterType
::
VectorValidPixelsRatioMapType
VectorValidPixelsRatioMapType
;
/** Return the ratio between valid pixels for each band and pixels in each label */
VectorValidPixelsRatioMapType
GetValidPixelsRatioMap
()
const
{
return
this
->
GetFilter
()
->
GetValidPixelsRatioMap
();
}
};
}
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbStreamingStatisticsMapFromLabelImageFilter2.hxx"
#endif
#endif
/* OTBSTREAMINGSTATISTICSMAPFROMLABELIMAGEFILTER2_H */
include/otbStreamingStatisticsMapFromLabelImageFilter2.hxx
0 → 100644
View file @
8f51af62
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: otbStreamingStatisticsMapFromLabelImageFilter2.hxx
* Author: otbuser
*
* Created on January 14, 2021, 12:54 AM
*/
#ifndef OTBSTREAMINGSTATISTICSMAPFROMLABELIMAGEFILTER2_HXX
#define OTBSTREAMINGSTATISTICSMAPFROMLABELIMAGEFILTER2_HXX
#include "otbStreamingStatisticsMapFromLabelImageFilter2.h"
namespace
otb
{
template
<
class
TInputVectorImage
,
class
TLabelImage
>
typename
PersistentStreamingStatisticsMapFromLabelImageFilter2
<
TInputVectorImage
,
TLabelImage
>::
VectorValidPixelsRatioMapType
PersistentStreamingStatisticsMapFromLabelImageFilter2
<
TInputVectorImage
,
TLabelImage
>::
GetValidPixelsRatioMap
()
const
{
return
m_CountPixel
;
}
template
<
class
TInputVectorImage
,
class
TLabelImage
>
void
PersistentStreamingStatisticsMapFromLabelImageFilter2
<
TInputVectorImage
,
TLabelImage
>::
Synthetize
()
{
// Update temporary accumulator
AccumulatorMapType
outputAcc
;
auto
endAcc
=
outputAcc
.
end
();
for
(
auto
const
&
threadAccMap
:
m_AccumulatorMaps
)
{
for
(
auto
const
&
it
:
threadAccMap
)
{
auto
label
=
it
.
first
;
auto
itAcc
=
outputAcc
.
find
(
label
);
if
(
itAcc
==
endAcc
)
{
outputAcc
.
emplace
(
label
,
it
.
second
);
}
else
{
itAcc
->
second
.
Update
(
it
.
second
);
}
}
}
// Publish output maps
for
(
auto
&
it
:
outputAcc
)
{
const
LabelPixelType
label
=
it
.
first
;
const
auto
&
bandCount
=
it
.
second
.
GetBandCount
();
const
auto
&
sum
=
it
.
second
.
GetSum
();
const
auto
&
sqSum
=
it
.
second
.
GetSqSum
();
// Count
m_LabelPopulation
[
label
]
=
it
.
second
.
GetCount
();
// Mean & stdev
RealVectorPixelType
mean
(
sum
);
RealVectorPixelType
std
(
sqSum
);
RealVectorValidPixelsRatioType
vectorcount
;
vectorcount
.
SetSize
(
mean
.
GetSize
());
for
(
unsigned
int
band
=
0
;
band
<
mean
.
GetSize
();
band
++
)
{
// Number of valid pixels in band
auto
count
=
bandCount
[
band
];
// Ratio of valid pixels
vectorcount
[
band
]
=
count
/
it
.
second
.
GetCount
();
// Mean
mean
[
band
]
/=
count
;
// Unbiased standard deviation (not sure unbiased is useful here)
const
double
variance
=
(
sqSum
[
band
]
-
(
sum
[
band
]
*
mean
[
band
]))
/
(
count
-
1
);
std
[
band
]
=
std
::
sqrt
(
variance
);
}
m_CountPixel
[
label
]
=
vectorcount
;
m_MeanRadiometricValue
[
label
]
=
mean
;
m_StDevRadiometricValue
[
label
]
=
std
;
// Min & max
m_MinRadiometricValue
[
label
]
=
it
.
second
.
GetMin
();
m_MaxRadiometricValue
[
label
]
=
it
.
second
.
GetMax
();
}
}
}
#endif
/* OTBSTREAMINGSTATISTICSMAPFROMLABELIMAGEFILTER2_HXX */
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