Merge branch 'master' of https://git.renater.fr/triskele into python
This commit is contained in:
commit
a36b683fd7
8
data/levelThresholds.txt
Normal file
8
data/levelThresholds.txt
Normal file
@ -0,0 +1,8 @@
|
||||
0
|
||||
1
|
||||
5
|
||||
10
|
||||
25
|
||||
50
|
||||
100
|
||||
200
|
@ -25,9 +25,10 @@ namespace otb {
|
||||
Selected selectedBand;
|
||||
size_t countingSortCeil = 2;
|
||||
vector<DimImg> areaThresholds;
|
||||
vector<double> sdThresholds, moiThresholds;
|
||||
vector<double> levelThresholds, sdThresholds, moiThresholds;
|
||||
unsigned int coreCount = boost::thread::hardware_concurrency ();
|
||||
bool maxTreeFlag = false, minTreeFlag = false, tosTreeFlag = false, alphaTreeFlag = false;
|
||||
bool averageFlag = false;
|
||||
bool oneBand = false;
|
||||
|
||||
Option ();
|
||||
|
@ -43,10 +43,10 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, WeightAttributes<Weigh
|
||||
auto start = high_resolution_clock::now ();
|
||||
switch (treeType) {
|
||||
case MIN:
|
||||
buildTree (tree, MinWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
||||
buildTree (tree, MaxWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
||||
break;
|
||||
case MAX:
|
||||
buildTree (tree, MaxWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
||||
buildTree (tree, MinWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
||||
break;
|
||||
case TOS:
|
||||
buildTree (tree, MedianWeight<PixelT, WeightT> (raster.getPixels (), graphWalker));
|
||||
@ -84,10 +84,10 @@ ArrayTreeBuilder<WeightT, PixelT>::setAttributProfiles (AttributeProfiles<PixelT
|
||||
attributeProfiles.updateTranscient ();
|
||||
switch (treeType) {
|
||||
case MIN:
|
||||
setAttributProfiles (attributeProfiles, MinWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
||||
setAttributProfiles (attributeProfiles, MaxWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
||||
break;
|
||||
case MAX:
|
||||
setAttributProfiles (attributeProfiles, MaxWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
||||
setAttributProfiles (attributeProfiles, MinWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
||||
break;
|
||||
case TOS:
|
||||
setAttributProfiles (attributeProfiles, MedianWeight<PixelT, WeightT> (raster.getPixels (), graphWalker));
|
||||
|
@ -45,7 +45,7 @@ namespace otb {
|
||||
};
|
||||
|
||||
/*! Structure intégrant la façon dont est géré un poids pour un MinTree */
|
||||
template <typename PixelT, typename WeightT> struct MinWeight : public WeightBase<PixelT, WeightT> {
|
||||
template <typename PixelT, typename WeightT> struct MaxWeight : public WeightBase<PixelT, WeightT> {
|
||||
typedef WeightBase<PixelT, WeightT> WB;
|
||||
|
||||
inline bool getDecr () const;
|
||||
@ -53,9 +53,9 @@ namespace otb {
|
||||
static inline bool isEdgeInf (const Edge<WeightT> &a, const Edge<WeightT> &b);
|
||||
static inline void sort (Edge<WeightT> *edges, DimEdge count);
|
||||
|
||||
inline MinWeight ();
|
||||
inline MinWeight (const PixelT *pixels, const Size &size);
|
||||
inline MinWeight (const MinWeight &model, const PixelT *pixels, const Size &size);
|
||||
inline MaxWeight ();
|
||||
inline MaxWeight (const PixelT *pixels, const Size &size);
|
||||
inline MaxWeight (const MaxWeight &model, const PixelT *pixels, const Size &size);
|
||||
|
||||
inline WeightT getWeight (const DimImg &idx) const;
|
||||
inline WeightT getWeight (const Point &a, const Point &b) const;
|
||||
@ -63,12 +63,12 @@ namespace otb {
|
||||
|
||||
// ========================================
|
||||
/*! Structure intégrant la façon dont est géré un poids pour un MaxTree */
|
||||
template <typename PixelT, typename WeightT> struct MaxWeight : public WeightBase<PixelT, WeightT> {
|
||||
template <typename PixelT, typename WeightT> struct MinWeight : public WeightBase<PixelT, WeightT> {
|
||||
typedef WeightBase<PixelT, WeightT> WB;
|
||||
|
||||
inline MaxWeight ();
|
||||
inline MaxWeight (const PixelT *pixels, const Size &size);
|
||||
inline MaxWeight (const MaxWeight &model, const PixelT *pixels, const Size &size);
|
||||
inline MinWeight ();
|
||||
inline MinWeight (const PixelT *pixels, const Size &size);
|
||||
inline MinWeight (const MinWeight &model, const PixelT *pixels, const Size &size);
|
||||
|
||||
inline WeightT getWeight (const DimImg &idx) const;
|
||||
inline WeightT getWeight (const Point &a, const Point &b) const;
|
||||
|
@ -101,60 +101,28 @@ WeightBase<PixelT, WeightT>::weight2valueBound (PixelT *compAPTree, const Weight
|
||||
// ========================================
|
||||
template <typename PixelT, typename WeightT>
|
||||
inline bool
|
||||
MinWeight<PixelT, WeightT>::getDecr () const {
|
||||
MaxWeight<PixelT, WeightT>::getDecr () const {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename PixelT, typename WeightT>
|
||||
inline bool
|
||||
MinWeight<PixelT, WeightT>::isWeightInf (const WeightT &a, const WeightT &b) {
|
||||
MaxWeight<PixelT, WeightT>::isWeightInf (const WeightT &a, const WeightT &b) {
|
||||
return a > b;
|
||||
}
|
||||
|
||||
template <typename PixelT, typename WeightT>
|
||||
inline bool
|
||||
MinWeight<PixelT, WeightT>::isEdgeInf (const Edge<WeightT> &a, const Edge<WeightT> &b) {
|
||||
MaxWeight<PixelT, WeightT>::isEdgeInf (const Edge<WeightT> &a, const Edge<WeightT> &b) {
|
||||
return isWeightInf (a.weight, b.weight);
|
||||
}
|
||||
|
||||
template <typename PixelT, typename WeightT>
|
||||
inline void
|
||||
MinWeight<PixelT, WeightT>::sort (Edge<WeightT> *edges, DimEdge count) {
|
||||
MaxWeight<PixelT, WeightT>::sort (Edge<WeightT> *edges, DimEdge count) {
|
||||
std::sort (edges, edges+count, isEdgeInf);
|
||||
}
|
||||
|
||||
template <typename PixelT, typename WeightT>
|
||||
inline
|
||||
MinWeight<PixelT, WeightT>::MinWeight ()
|
||||
: WB (nullptr, NullSize) {
|
||||
}
|
||||
|
||||
template <typename PixelT, typename WeightT>
|
||||
inline
|
||||
MinWeight<PixelT, WeightT>::MinWeight (const PixelT *pixels, const Size &size)
|
||||
: WB (pixels, size) {
|
||||
}
|
||||
|
||||
template <typename PixelT, typename WeightT>
|
||||
inline
|
||||
MinWeight<PixelT, WeightT>::MinWeight (const MinWeight &model, const PixelT *pixels, const Size &size)
|
||||
: WB (pixels, size) {
|
||||
}
|
||||
|
||||
template <typename PixelT, typename WeightT>
|
||||
inline WeightT
|
||||
MinWeight<PixelT, WeightT>::getWeight (const DimImg &idx) const {
|
||||
return WB::getValue (idx);
|
||||
}
|
||||
|
||||
template <typename PixelT, typename WeightT>
|
||||
inline WeightT
|
||||
MinWeight<PixelT, WeightT>::getWeight (const Point &a, const Point &b) const {
|
||||
return std::min (getWeight (WB::pointIdx (a)),
|
||||
getWeight (WB::pointIdx (b)));
|
||||
}
|
||||
|
||||
// ========================================
|
||||
template <typename PixelT, typename WeightT>
|
||||
inline
|
||||
MaxWeight<PixelT, WeightT>::MaxWeight ()
|
||||
@ -182,6 +150,38 @@ MaxWeight<PixelT, WeightT>::getWeight (const DimImg &idx) const {
|
||||
template <typename PixelT, typename WeightT>
|
||||
inline WeightT
|
||||
MaxWeight<PixelT, WeightT>::getWeight (const Point &a, const Point &b) const {
|
||||
return std::min (getWeight (WB::pointIdx (a)),
|
||||
getWeight (WB::pointIdx (b)));
|
||||
}
|
||||
|
||||
// ========================================
|
||||
template <typename PixelT, typename WeightT>
|
||||
inline
|
||||
MinWeight<PixelT, WeightT>::MinWeight ()
|
||||
: WB (nullptr, NullSize) {
|
||||
}
|
||||
|
||||
template <typename PixelT, typename WeightT>
|
||||
inline
|
||||
MinWeight<PixelT, WeightT>::MinWeight (const PixelT *pixels, const Size &size)
|
||||
: WB (pixels, size) {
|
||||
}
|
||||
|
||||
template <typename PixelT, typename WeightT>
|
||||
inline
|
||||
MinWeight<PixelT, WeightT>::MinWeight (const MinWeight &model, const PixelT *pixels, const Size &size)
|
||||
: WB (pixels, size) {
|
||||
}
|
||||
|
||||
template <typename PixelT, typename WeightT>
|
||||
inline WeightT
|
||||
MinWeight<PixelT, WeightT>::getWeight (const DimImg &idx) const {
|
||||
return WB::getValue (idx);
|
||||
}
|
||||
|
||||
template <typename PixelT, typename WeightT>
|
||||
inline WeightT
|
||||
MinWeight<PixelT, WeightT>::getWeight (const Point &a, const Point &b) const {
|
||||
return std::max (getWeight (WB::pointIdx (a)),
|
||||
getWeight (WB::pointIdx (b)));
|
||||
}
|
||||
|
@ -16,6 +16,9 @@ namespace otb {
|
||||
inline PixelT *getValues ();
|
||||
inline const PixelT *getValues () const;
|
||||
|
||||
template<typename WeightT>
|
||||
inline void setValues (const PixelT *pixels, const WeightT *weights);
|
||||
|
||||
protected:
|
||||
const Tree &tree;
|
||||
DimNodeId leafCount;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP
|
||||
#define _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP
|
||||
|
||||
// ========================================
|
||||
template<typename PixelT>
|
||||
inline
|
||||
AttributeProfiles<PixelT>::AttributeProfiles (const Tree &tree)
|
||||
@ -34,6 +35,25 @@ AttributeProfiles<PixelT>::getValues () const {
|
||||
return &values[0];
|
||||
}
|
||||
|
||||
// ========================================
|
||||
template<typename PixelT>
|
||||
template<typename WeightT>
|
||||
inline void
|
||||
AttributeProfiles<PixelT>::setValues (const PixelT *pixels, const WeightT *weights) {
|
||||
updateTranscient ();
|
||||
PixelT *leafAP = &values[0];
|
||||
dealThreadBound (tree.getLeafCount (), tree.getCoreCount (), [&leafAP, &pixels] (const DimImg &minVal, const DimImg &maxVal) {
|
||||
for (DimImg i = minVal; i < maxVal; ++i)
|
||||
leafAP[i] = pixels [i];
|
||||
});
|
||||
PixelT *compAP = leafAP+tree.getLeafCount ();
|
||||
dealThreadBound (tree.getCompCount (), tree.getCoreCount (), [&compAP, &weights] (const DimImg &minVal, const DimImg &maxVal) {
|
||||
for (DimImg compIdx = minVal; compIdx < maxVal; ++compIdx)
|
||||
compAP[compIdx] = weights[compIdx];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
template<typename PixelT>
|
||||
inline void
|
||||
AttributeProfiles<PixelT>::free () {
|
||||
@ -58,4 +78,5 @@ AttributeProfiles<PixelT>::print (ostream &out) const {
|
||||
return out;
|
||||
}
|
||||
|
||||
// ========================================
|
||||
#endif // _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP
|
||||
|
@ -9,7 +9,7 @@
|
||||
namespace otb {
|
||||
namespace triskele {
|
||||
|
||||
class AreaAttributes : public CompAttributeC<DimImg> {
|
||||
class AreaAttributes : public CompAttribute<DimImg> {
|
||||
public:
|
||||
inline AreaAttributes (const Tree &tree);
|
||||
inline ~AreaAttributes ();
|
||||
|
@ -5,7 +5,7 @@ using namespace boost::chrono;
|
||||
|
||||
inline
|
||||
AreaAttributes::AreaAttributes (const Tree &tree)
|
||||
: CompAttributeC<DimImg> (tree) {
|
||||
: CompAttribute<DimImg> (tree) {
|
||||
compute ();
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ inline void
|
||||
AreaAttributes::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||
const vector<DimImg> &thresholds) const {
|
||||
auto start = high_resolution_clock::now ();
|
||||
CompAttributeC<DimImg>::cut (allBands, attributeProfiles, 1, thresholds);
|
||||
CompAttribute<DimImg>::cut (allBands, attributeProfiles, 1, thresholds);
|
||||
globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
|
||||
}
|
||||
|
||||
|
@ -11,11 +11,12 @@
|
||||
namespace otb {
|
||||
namespace triskele {
|
||||
|
||||
class AverageAttributes : public CompAttributeC<double> {
|
||||
class AverageAttributes : public CompAttribute<double> {
|
||||
public:
|
||||
template<typename PixelT>
|
||||
inline AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes);
|
||||
inline ~AverageAttributes ();
|
||||
|
||||
virtual inline ostream &print (ostream &out) const { CompAttribute::print (out, "average"); return out; }
|
||||
protected:
|
||||
template<typename PixelT>
|
||||
|
@ -6,7 +6,7 @@ using namespace boost::chrono;
|
||||
template<typename PixelT>
|
||||
inline
|
||||
AverageAttributes::AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes)
|
||||
: CompAttributeC<double> (tree) {
|
||||
: CompAttribute<double> (tree) {
|
||||
compute (raster, areaAttributes);
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
namespace otb {
|
||||
namespace triskele {
|
||||
|
||||
class MoIAttributes : public CompAttributeC<double> {
|
||||
class MoIAttributes : public CompAttribute<double> {
|
||||
public:
|
||||
inline MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes);
|
||||
inline ~MoIAttributes ();
|
||||
|
@ -5,7 +5,7 @@ using namespace boost::chrono;
|
||||
|
||||
inline
|
||||
MoIAttributes::MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes)
|
||||
: CompAttributeC<double> (tree) {
|
||||
: CompAttribute<double> (tree) {
|
||||
compute (areaAttributes, xyAttributes);
|
||||
}
|
||||
|
||||
@ -23,8 +23,8 @@ MoIAttributes::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<P
|
||||
auto start = high_resolution_clock::now ();
|
||||
double maxValue = CompAttribute<double>::getMaxValue ();
|
||||
cerr << "moi max value:" << maxValue << endl;
|
||||
CompAttributeC<double>::cut (allBands, attributeProfiles, 0,
|
||||
CompAttributeC<double>::getScaledThresholds (thresholds, maxValue));
|
||||
CompAttribute<double>::cut (allBands, attributeProfiles, 0,
|
||||
CompAttribute<double>::getScaledThresholds (thresholds, maxValue));
|
||||
globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
namespace otb {
|
||||
namespace triskele {
|
||||
|
||||
class SDAttributes : public CompAttributeC<double> {
|
||||
class SDAttributes : public CompAttribute<double> {
|
||||
public:
|
||||
inline SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes);
|
||||
inline ~SDAttributes ();
|
||||
|
@ -5,7 +5,7 @@ using namespace boost::chrono;
|
||||
|
||||
inline
|
||||
SDAttributes::SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes)
|
||||
: CompAttributeC<double> (tree) {
|
||||
: CompAttribute<double> (tree) {
|
||||
compute (areaAttributes);
|
||||
}
|
||||
|
||||
@ -23,8 +23,8 @@ SDAttributes::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<Pi
|
||||
auto start = high_resolution_clock::now ();
|
||||
double maxValue = CompAttribute<double>::getMaxValue ();
|
||||
cerr << "sd max value:" << maxValue << endl;
|
||||
CompAttributeC<double>::cut (allBands, attributeProfiles, 0,
|
||||
CompAttributeC<double>::getScaledThresholds (thresholds, maxValue));
|
||||
CompAttribute<double>::cut (allBands, attributeProfiles, 0,
|
||||
CompAttribute<double>::getScaledThresholds (thresholds, maxValue));
|
||||
globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
#ifndef _OTB_TRISKELE_WEIGHT_ATTRIBUTES_HPP
|
||||
#define _OTB_TRISKELE_WEIGHT_ATTRIBUTES_HPP
|
||||
|
||||
#include <boost/chrono.hpp>
|
||||
|
||||
#include "triskeleBase.hpp"
|
||||
|
||||
namespace otb {
|
||||
@ -15,6 +17,9 @@ namespace otb {
|
||||
inline ~WeightAttributes ();
|
||||
|
||||
inline void setWeightBounds (Tree &tree);
|
||||
template<typename PixelT>
|
||||
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||
const vector<WeightT> &thresholds) const;
|
||||
|
||||
virtual inline ostream &print (ostream &out) const { CompAttribute<WeightT>::print (out, "weight"); return out; }
|
||||
};
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef _OTB_TRISKELE_WEIGHT_ATTRIBUTES_TPP
|
||||
#define _OTB_TRISKELE_WEIGHT_ATTRIBUTES_TPP
|
||||
|
||||
using namespace boost::chrono;
|
||||
|
||||
template<typename WeightT>
|
||||
inline
|
||||
WeightAttributes<WeightT>::WeightAttributes (const Tree &tree)
|
||||
@ -39,4 +41,16 @@ WeightAttributes<WeightT>::setWeightBounds (Tree &tree) {
|
||||
weightBounds.push_back (rootId+1);
|
||||
}
|
||||
|
||||
|
||||
template<typename WeightT>
|
||||
template<typename PixelT>
|
||||
inline void
|
||||
WeightAttributes<WeightT>::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||
const vector<WeightT> &thresholds) const {
|
||||
auto start = high_resolution_clock::now ();
|
||||
CompAttribute<WeightT>::cut (allBands, attributeProfiles, 0., thresholds);
|
||||
globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
|
||||
}
|
||||
|
||||
|
||||
#endif // _OTB_TRISKELE_WEIGHT_ATTRIBUTES_TPP
|
||||
|
@ -18,7 +18,7 @@ namespace otb {
|
||||
operator DimImg () const { return (DimImg) (x*y); }
|
||||
};
|
||||
|
||||
class XYAttributes : public CompAttributeC<AverageXY> {
|
||||
class XYAttributes : public CompAttribute<AverageXY> {
|
||||
public:
|
||||
inline XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes);
|
||||
inline ~XYAttributes ();
|
||||
|
@ -5,7 +5,7 @@ using namespace boost::chrono;
|
||||
|
||||
inline
|
||||
XYAttributes::XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes)
|
||||
: CompAttributeC<AverageXY> (tree) {
|
||||
: CompAttribute<AverageXY> (tree) {
|
||||
compute (areaAttributes);
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,9 @@ namespace otb {
|
||||
template<typename AttrT>
|
||||
class CompAttribute {
|
||||
public:
|
||||
static inline vector<AttrT> getScaledThresholds (const vector<double> &thresholds, const AttrT &maxValue);
|
||||
static inline vector<AttrT> getConvertedThresholds (const vector<double> &thresholds);
|
||||
|
||||
inline CompAttribute (const Tree &tree);
|
||||
inline ~CompAttribute ();
|
||||
|
||||
@ -22,6 +25,14 @@ namespace otb {
|
||||
inline AttrT *getValues ();
|
||||
inline AttrT getMaxValue () const;
|
||||
|
||||
template<typename PixelT>
|
||||
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||
const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const;
|
||||
|
||||
template<typename PixelT>
|
||||
inline void cutOnPos (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||
const DimImg &pixelId, const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const;
|
||||
|
||||
virtual inline ostream &print (ostream &out) const { print (out, ""); return out; }
|
||||
|
||||
protected:
|
||||
@ -32,39 +43,19 @@ namespace otb {
|
||||
inline void free ();
|
||||
inline void book (const DimImg &leafCount);
|
||||
|
||||
template<typename CumpFunctPSE>
|
||||
inline void computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE /* cumpFunctPSE (DimImg parentId)*/) const;
|
||||
|
||||
ostream &print (ostream &out, const string &msg) const;
|
||||
friend ostream &operator << (ostream& out, const CompAttribute &ca) { return ca.print (out); }
|
||||
friend ostream &operator << (ostream& out, const CompAttribute &ca) { return ca.print (out); return out; }
|
||||
|
||||
};
|
||||
|
||||
} // triskele
|
||||
} // otb
|
||||
|
||||
#include "Attributes/WeightAttributes.hpp"
|
||||
|
||||
namespace otb {
|
||||
namespace triskele {
|
||||
|
||||
template<typename AttrT>
|
||||
class CompAttributeC : public CompAttribute<AttrT> {
|
||||
public:
|
||||
inline CompAttributeC (const Tree &tree);
|
||||
inline ~CompAttributeC ();
|
||||
|
||||
static inline vector<AttrT> getScaledThresholds (const vector<double> &thresholds, const AttrT &maxValue);
|
||||
|
||||
template<typename PixelT>
|
||||
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||
const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const;
|
||||
|
||||
template<typename PixelT>
|
||||
inline void cutOnPos (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||
const DimImg &pixelId, const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const;
|
||||
|
||||
protected:
|
||||
template<typename CumpFunctPSE>
|
||||
inline void computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE /* cumpFunctPSE (DimImg parentId)*/) const;
|
||||
};
|
||||
|
||||
#include "CompAttribute.tpp"
|
||||
} // triskele
|
||||
} // otb
|
||||
|
@ -1,6 +1,26 @@
|
||||
#ifndef _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
|
||||
#define _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
|
||||
|
||||
// ========================================
|
||||
template<typename AttrT>
|
||||
inline vector<AttrT>
|
||||
CompAttribute<AttrT>::getScaledThresholds (const vector<double> &thresholds, const AttrT &maxValue) {
|
||||
vector<AttrT> result;
|
||||
for (double percent : thresholds)
|
||||
result.push_back (percent*maxValue);
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename AttrT>
|
||||
inline vector<AttrT>
|
||||
CompAttribute<AttrT>::getConvertedThresholds (const vector<double> &thresholds) {
|
||||
vector<AttrT> result;
|
||||
for (double value : thresholds)
|
||||
result.push_back ((AttrT) value);
|
||||
return result;
|
||||
}
|
||||
|
||||
// ========================================
|
||||
template<typename AttrT>
|
||||
inline
|
||||
CompAttribute<AttrT>::CompAttribute (const Tree &tree)
|
||||
@ -47,78 +67,13 @@ CompAttribute<AttrT>::getMaxValue () const {
|
||||
return max;
|
||||
}
|
||||
|
||||
template<typename AttrT>
|
||||
inline ostream &
|
||||
CompAttribute<AttrT>::print (ostream &out, const string &msg) const {
|
||||
cout << "values: " << msg << endl;
|
||||
const Size doubleSize (tree.getSize().width, 2*tree.getSize ().height);
|
||||
return cout << printMap (&values[0], doubleSize, tree.getCompCount ()) << endl << endl;
|
||||
}
|
||||
|
||||
template<typename AttrT>
|
||||
inline void
|
||||
CompAttribute<AttrT>::free () {
|
||||
values = vector<AttrT> ();
|
||||
}
|
||||
|
||||
template<typename AttrT>
|
||||
inline void
|
||||
CompAttribute<AttrT>::book (const DimImg &leafCount) {
|
||||
this->leafCount = leafCount;
|
||||
values.resize (leafCount);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
template<typename AttrT>
|
||||
inline
|
||||
CompAttributeC<AttrT>::CompAttributeC (const Tree &tree)
|
||||
: CompAttribute<AttrT> (tree) {
|
||||
}
|
||||
|
||||
template<typename AttrT>
|
||||
inline
|
||||
CompAttributeC<AttrT>::~CompAttributeC () {
|
||||
}
|
||||
|
||||
template<typename AttrT>
|
||||
inline vector<AttrT>
|
||||
CompAttributeC<AttrT>::getScaledThresholds (const vector<double> &thresholds, const AttrT &maxValue) {
|
||||
vector<AttrT> result;
|
||||
for (AttrT percent : thresholds)
|
||||
result.push_back (percent*maxValue);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
template<typename AttrT>
|
||||
template<typename CumpFunctPSE>
|
||||
inline void
|
||||
CompAttributeC<AttrT>::computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE) const {
|
||||
const vector<DimImg> &weightBounds (CompAttribute<AttrT>::tree.getWeightBounds ());
|
||||
unsigned int coreCount = CompAttribute<AttrT>::tree.getCoreCount ();
|
||||
DEF_LOG ("CompAttributeC::computeSameCompLevel", "coreCount:" << coreCount);
|
||||
if (!weightBounds.size () || CompAttribute<AttrT>::tree.getCompCount ()/weightBounds.size () < coreCount) {
|
||||
LOG ("CompAttributeC::computeSameCompLevel: no thread");
|
||||
CompAttribute<AttrT>::tree.forEachComp (cumpFunctPSE);
|
||||
return;
|
||||
}
|
||||
DimImg first = weightBounds [0];
|
||||
for (DimImg curBound = 1; curBound < weightBounds.size (); curBound++) {
|
||||
DimImg next = weightBounds [curBound];
|
||||
dealThreadRange (next-first, coreCount, [this, &first, &cumpFunctPSE] (const DimImg &id) {
|
||||
const DimImg parentId = id+first;
|
||||
cumpFunctPSE (parentId);
|
||||
});
|
||||
first = next;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename AttrT>
|
||||
template<typename PixelT>
|
||||
inline void
|
||||
CompAttributeC<AttrT>::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||
CompAttribute<AttrT>::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||
const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const {
|
||||
DEF_LOG ("CompAttributeC::cut", "coreCount:" << CompAttribute<AttrT>::tree.getCoreCount () << " thresholds:" << thresholds.size ());
|
||||
DEF_LOG ("CompAttribute::cut", "coreCount:" << CompAttribute<AttrT>::tree.getCoreCount () << " thresholds:" << thresholds.size ());
|
||||
dealThreadRange (CompAttribute<AttrT>::leafCount, CompAttribute<AttrT>::tree.getCoreCount (), [this, &allBands, &attributeProfiles, &pixelAttrValue, &thresholds] (const DimImg &leafId) {
|
||||
cutOnPos (allBands, attributeProfiles, leafId, pixelAttrValue, thresholds);
|
||||
});
|
||||
@ -127,7 +82,7 @@ CompAttributeC<AttrT>::cut (vector<vector<PixelT> > &allBands, const AttributePr
|
||||
template<typename AttrT>
|
||||
template<typename PixelT>
|
||||
inline void
|
||||
CompAttributeC<AttrT>::cutOnPos (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||
CompAttribute<AttrT>::cutOnPos (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||
const DimImg &leafId, const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const {
|
||||
// no debug (to many pixels)
|
||||
DimImg parentId = CompAttribute<AttrT>::tree.getLeafParent (leafId);
|
||||
@ -152,7 +107,7 @@ CompAttributeC<AttrT>::cutOnPos (vector<vector<PixelT> > &allBands, const Attrib
|
||||
AttrT ceil = thresholds[chanel];
|
||||
for ( ; curValue < ceil && curId < rootId; ) {
|
||||
if (parentId == DimImg_MAX || curId >= parentId) {
|
||||
// cerr << "CompAttributeC::cutOnPos find sub-root:" << rootId << " rootId:" << rootId << endl;
|
||||
// cerr << "CompAttribute::cutOnPos find sub-root:" << rootId << " rootId:" << rootId << endl;
|
||||
for (; chanel < thresholdsSize; ++chanel)
|
||||
allBands[chanel][leafId] = curValue;
|
||||
return;
|
||||
@ -167,4 +122,53 @@ CompAttributeC<AttrT>::cutOnPos (vector<vector<PixelT> > &allBands, const Attrib
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
template<typename AttrT>
|
||||
inline ostream &
|
||||
CompAttribute<AttrT>::print (ostream &out, const string &msg) const {
|
||||
cout << "values: " << msg << endl;
|
||||
const Size doubleSize (tree.getSize().width, 2*tree.getSize ().height);
|
||||
cout << printMap (&values[0], doubleSize, tree.getCompCount ()) << endl << endl;
|
||||
return out;
|
||||
}
|
||||
|
||||
// ========================================
|
||||
template<typename AttrT>
|
||||
inline void
|
||||
CompAttribute<AttrT>::free () {
|
||||
values = vector<AttrT> ();
|
||||
}
|
||||
|
||||
template<typename AttrT>
|
||||
inline void
|
||||
CompAttribute<AttrT>::book (const DimImg &leafCount) {
|
||||
this->leafCount = leafCount;
|
||||
values.resize (leafCount);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
template<typename AttrT>
|
||||
template<typename CumpFunctPSE>
|
||||
inline void
|
||||
CompAttribute<AttrT>::computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE) const {
|
||||
const vector<DimImg> &weightBounds (CompAttribute<AttrT>::tree.getWeightBounds ());
|
||||
unsigned int coreCount = CompAttribute<AttrT>::tree.getCoreCount ();
|
||||
DEF_LOG ("CompAttribute::computeSameCompLevel", "coreCount:" << coreCount);
|
||||
if (!weightBounds.size () || CompAttribute<AttrT>::tree.getCompCount ()/weightBounds.size () < coreCount) {
|
||||
LOG ("CompAttribute::computeSameCompLevel: no thread");
|
||||
CompAttribute<AttrT>::tree.forEachComp (cumpFunctPSE);
|
||||
return;
|
||||
}
|
||||
DimImg first = weightBounds [0];
|
||||
for (DimImg curBound = 1; curBound < weightBounds.size (); curBound++) {
|
||||
DimImg next = weightBounds [curBound];
|
||||
dealThreadRange (next-first, coreCount, [this, &first, &cumpFunctPSE] (const DimImg &id) {
|
||||
const DimImg parentId = id+first;
|
||||
cumpFunctPSE (parentId);
|
||||
});
|
||||
first = next;
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================
|
||||
#endif // _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
|
||||
|
@ -71,7 +71,7 @@ dealThread (const DimImg &maxId, unsigned int coreCount, const FunctThreadMinMax
|
||||
functThreadMinMax (idCopyValInThread, maxIds[idCopyValInThread], maxIds[idCopyValInThread+1]);
|
||||
});
|
||||
#else /* BOOST thread */
|
||||
boost::thread tasks [coreCount];
|
||||
std::vector<boost::thread> tasks;
|
||||
for (unsigned int idCopyValInThread = 0; idCopyValInThread < coreCount; ++idCopyValInThread) {
|
||||
tasks.push_back (boost::thread ([/*no ref!!!*/idCopyValInThread, &maxIds, &functThreadMinMax] () {
|
||||
functThreadMinMax (idCopyValInThread, maxIds[idCopyValInThread], maxIds[idCopyValInThread+1]);
|
||||
@ -106,37 +106,37 @@ callOnSortedSets (const std::vector<DimImg> &sizes,
|
||||
// get min
|
||||
bool found = false;
|
||||
DimImg minVectIdx = 0;
|
||||
WeightT minWeight = 0;
|
||||
WeightT maxWeight = 0;
|
||||
for (DimImg vectId = 0; vectId < size; ++vectId) {
|
||||
if (!vectCounts [vectId])
|
||||
continue;
|
||||
WeightT tmpWeight = getWeight (vectId, 0);
|
||||
if (found && !isWeightInf (tmpWeight, minWeight))
|
||||
if (found && !isWeightInf (tmpWeight, maxWeight))
|
||||
continue;
|
||||
minVectIdx = vectId;
|
||||
minWeight = tmpWeight;
|
||||
maxWeight = tmpWeight;
|
||||
found = true;
|
||||
}
|
||||
LOG ("found:" << found << " minVectIdx:" << minVectIdx << " minWeight:" << minWeight);
|
||||
LOG ("found:" << found << " minVectIdx:" << minVectIdx << " maxWeight:" << maxWeight);
|
||||
// loop
|
||||
for ( ; found; ) {
|
||||
// get next min
|
||||
found = false;
|
||||
DimImg nextMinVectIdx = 0;
|
||||
WeightT nextMinWeight = 0;
|
||||
WeightT nextMaxWeight = 0;
|
||||
for (DimImg vectId = minVectIdx; ; ) {
|
||||
if (vectCounts [vectId]) {
|
||||
WeightT tmpWeight = getWeight (vectId, vectIds [vectId]);
|
||||
if (!isWeightInf (minWeight, tmpWeight)) {
|
||||
// minWeight == tmpWeight
|
||||
if (!isWeightInf (maxWeight, tmpWeight)) {
|
||||
// maxWeight == tmpWeight
|
||||
callIdId (vectId, vectIds [vectId]);
|
||||
++vectIds [vectId];
|
||||
--vectCounts [vectId];
|
||||
continue;
|
||||
}
|
||||
if (!found || isWeightInf (tmpWeight, nextMinWeight)) {
|
||||
if (!found || isWeightInf (tmpWeight, nextMaxWeight)) {
|
||||
nextMinVectIdx = vectId;
|
||||
nextMinWeight = tmpWeight;
|
||||
nextMaxWeight = tmpWeight;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
@ -145,7 +145,7 @@ callOnSortedSets (const std::vector<DimImg> &sizes,
|
||||
break;
|
||||
}
|
||||
minVectIdx = nextMinVectIdx;
|
||||
minWeight = nextMinWeight;
|
||||
maxWeight = nextMaxWeight;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ Option::parse (int argc, char** argv) {
|
||||
bool helpFlag = false, versionFlag = false, useTheForceLuke = false;
|
||||
string inputFileName, outputFileName, bandsRange;
|
||||
long left = -1, top = -1, width = -1, height = -1;
|
||||
string areaThresholdsName, sdThresholdsName, moiThresholdsName;
|
||||
string areaThresholdsName, levelThresholdsName, sdThresholdsName, moiThresholdsName;
|
||||
try {
|
||||
desc.add_options ()
|
||||
("help", po::bool_switch (&helpFlag), "produce this help message")
|
||||
@ -110,10 +110,14 @@ Option::parse (int argc, char** argv) {
|
||||
("height,h", po::value<long> (&height), "height crop (default input height)")
|
||||
("input,i", po::value<string> (&inputFileName), "input file name image")
|
||||
("output,o", po::value<string> (&outputFileName), "output file name hyperbands image (contains attributs profiles)")
|
||||
("average", po::bool_switch (&averageFlag), "produce average profiles")
|
||||
|
||||
("max-tree", po::bool_switch (&maxTreeFlag), "build max-tree")
|
||||
("min-tree", po::bool_switch (&minTreeFlag), "build min-tree")
|
||||
("tos-tree", po::bool_switch (&tosTreeFlag), "build tree-of-shape")
|
||||
("alpha-tree", po::bool_switch (&alphaTreeFlag), "build alpha-tree")
|
||||
|
||||
("level,L", po::value<string> (&levelThresholdsName), "produce level attributs")
|
||||
("area,A", po::value<string> (&areaThresholdsName), "produce area attributs")
|
||||
("standard-deviation,S", po::value<string> (&sdThresholdsName), "produce standard deviation attributs")
|
||||
("moment-of-inertia,M", po::value<string> (&moiThresholdsName), "produce moment of inertia attributs")
|
||||
@ -186,6 +190,7 @@ Option::parse (int argc, char** argv) {
|
||||
usage ("Bad options");
|
||||
}
|
||||
areaThresholds = readThresholds<DimImg> (areaThresholdsName);
|
||||
levelThresholds = readThresholds<double> (levelThresholdsName);
|
||||
sdThresholds = readThresholds<double> (sdThresholdsName);
|
||||
moiThresholds = readThresholds<double> (moiThresholdsName);
|
||||
|
||||
|
@ -24,7 +24,7 @@ IImage::~IImage () {
|
||||
|
||||
void
|
||||
IImage::readImage () {
|
||||
DEF_LOG ("IImage::readImage", "fileName: " << fileName);
|
||||
DEF_LOG ("IImage::readImage", "fileName: " << fileName << " c_str:" << fileName.c_str ());
|
||||
BOOST_ASSERT (gdalInputDataset == nullptr);
|
||||
BOOST_ASSERT (gdalOutputDataset == nullptr);
|
||||
close ();
|
||||
|
@ -69,10 +69,10 @@ void apGenerator (Option &option) {
|
||||
Border border (option.size, false); // default = no border
|
||||
GraphWalker graphWalker (border);
|
||||
DimImg leafCount = graphWalker.vertexMaxCount ();
|
||||
DimChanel maxThresholds = max (max (option.areaThresholds.size (), option.sdThresholds.size ()), option.moiThresholds.size ());
|
||||
DimChanel maxThresholds = max (max (max (option.areaThresholds.size (), option.levelThresholds.size ()), option.sdThresholds.size ()), option.moiThresholds.size ());
|
||||
vector <vector <PixelT> > allBands (maxThresholds, vector<PixelT> (leafCount, 0));
|
||||
|
||||
DimChanel outputBandsCard = option.selectedBand.getSet ().size ()*(1+treeTypesCard*(option.areaThresholds.size ()+option.sdThresholds.size ()+option.moiThresholds.size ()));
|
||||
DimChanel outputBandsCard = option.selectedBand.getSet ().size ()*(1+treeTypesCard*(option.areaThresholds.size ()+option.levelThresholds.size ()+option.sdThresholds.size ()+option.moiThresholds.size ()));
|
||||
if (!option.oneBand)
|
||||
option.outputImage.createImage (option.size, option.inputImage.getDataType (), outputBandsCard);
|
||||
|
||||
@ -88,9 +88,21 @@ void apGenerator (Option &option) {
|
||||
WeightAttributes<PixelT> weightAttributes (tree);
|
||||
atb.buildTree (tree, weightAttributes);
|
||||
AttributeProfiles<PixelT> attributeProfiles (tree);
|
||||
atb.setAttributProfiles (attributeProfiles);
|
||||
|
||||
AreaAttributes areaAttributes (tree);
|
||||
AverageAttributes averageAttributes (tree, raster, areaAttributes);
|
||||
|
||||
if (option.averageFlag)
|
||||
attributeProfiles.setValues (raster.getPixels (), averageAttributes.getValues ());
|
||||
else
|
||||
atb.setAttributProfiles (attributeProfiles);
|
||||
|
||||
if (option.levelThresholds.size ()) {
|
||||
vector<PixelT> thresholds (weightAttributes.getConvertedThresholds (option.levelThresholds));
|
||||
weightAttributes.cut (allBands, attributeProfiles, thresholds);
|
||||
for (DimChanel c = 0; c < option.levelThresholds.size (); ++c, ++chanel)
|
||||
writeBand (option, &allBands[c][0], chanel);
|
||||
}
|
||||
if (option.areaThresholds.size ()) {
|
||||
areaAttributes.cut (allBands, attributeProfiles, option.areaThresholds);
|
||||
for (DimChanel c = 0; c < option.areaThresholds.size (); ++c, ++chanel)
|
||||
|
Loading…
Reference in New Issue
Block a user