Merge branch 'master' of https://git.renater.fr/triskele into python

This commit is contained in:
Florent Guiotte 2018-05-31 16:02:10 +02:00
commit a36b683fd7
25 changed files with 239 additions and 174 deletions

8
data/levelThresholds.txt Normal file
View File

@ -0,0 +1,8 @@
0
1
5
10
25
50
100
200

View File

@ -25,9 +25,10 @@ namespace otb {
Selected selectedBand; Selected selectedBand;
size_t countingSortCeil = 2; size_t countingSortCeil = 2;
vector<DimImg> areaThresholds; vector<DimImg> areaThresholds;
vector<double> sdThresholds, moiThresholds; vector<double> levelThresholds, sdThresholds, moiThresholds;
unsigned int coreCount = boost::thread::hardware_concurrency (); unsigned int coreCount = boost::thread::hardware_concurrency ();
bool maxTreeFlag = false, minTreeFlag = false, tosTreeFlag = false, alphaTreeFlag = false; bool maxTreeFlag = false, minTreeFlag = false, tosTreeFlag = false, alphaTreeFlag = false;
bool averageFlag = false;
bool oneBand = false; bool oneBand = false;
Option (); Option ();

View File

@ -43,10 +43,10 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, WeightAttributes<Weigh
auto start = high_resolution_clock::now (); auto start = high_resolution_clock::now ();
switch (treeType) { switch (treeType) {
case MIN: case MIN:
buildTree (tree, MinWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ())); buildTree (tree, MaxWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
break; break;
case MAX: case MAX:
buildTree (tree, MaxWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ())); buildTree (tree, MinWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
break; break;
case TOS: case TOS:
buildTree (tree, MedianWeight<PixelT, WeightT> (raster.getPixels (), graphWalker)); buildTree (tree, MedianWeight<PixelT, WeightT> (raster.getPixels (), graphWalker));
@ -84,10 +84,10 @@ ArrayTreeBuilder<WeightT, PixelT>::setAttributProfiles (AttributeProfiles<PixelT
attributeProfiles.updateTranscient (); attributeProfiles.updateTranscient ();
switch (treeType) { switch (treeType) {
case MIN: case MIN:
setAttributProfiles (attributeProfiles, MinWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ())); setAttributProfiles (attributeProfiles, MaxWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
break; break;
case MAX: case MAX:
setAttributProfiles (attributeProfiles, MaxWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ())); setAttributProfiles (attributeProfiles, MinWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
break; break;
case TOS: case TOS:
setAttributProfiles (attributeProfiles, MedianWeight<PixelT, WeightT> (raster.getPixels (), graphWalker)); setAttributProfiles (attributeProfiles, MedianWeight<PixelT, WeightT> (raster.getPixels (), graphWalker));

View File

@ -45,7 +45,7 @@ namespace otb {
}; };
/*! Structure intégrant la façon dont est géré un poids pour un MinTree */ /*! 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; typedef WeightBase<PixelT, WeightT> WB;
inline bool getDecr () const; inline bool getDecr () const;
@ -53,9 +53,9 @@ namespace otb {
static inline bool isEdgeInf (const Edge<WeightT> &a, const Edge<WeightT> &b); static inline bool isEdgeInf (const Edge<WeightT> &a, const Edge<WeightT> &b);
static inline void sort (Edge<WeightT> *edges, DimEdge count); static inline void sort (Edge<WeightT> *edges, DimEdge count);
inline MinWeight (); inline MaxWeight ();
inline MinWeight (const PixelT *pixels, const Size &size); inline MaxWeight (const PixelT *pixels, const Size &size);
inline MinWeight (const MinWeight &model, 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 DimImg &idx) const;
inline WeightT getWeight (const Point &a, const Point &b) 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 */ /*! 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; typedef WeightBase<PixelT, WeightT> WB;
inline MaxWeight (); inline MinWeight ();
inline MaxWeight (const PixelT *pixels, const Size &size); inline MinWeight (const PixelT *pixels, const Size &size);
inline MaxWeight (const MaxWeight &model, 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 DimImg &idx) const;
inline WeightT getWeight (const Point &a, const Point &b) const; inline WeightT getWeight (const Point &a, const Point &b) const;

View File

@ -101,60 +101,28 @@ WeightBase<PixelT, WeightT>::weight2valueBound (PixelT *compAPTree, const Weight
// ======================================== // ========================================
template <typename PixelT, typename WeightT> template <typename PixelT, typename WeightT>
inline bool inline bool
MinWeight<PixelT, WeightT>::getDecr () const { MaxWeight<PixelT, WeightT>::getDecr () const {
return true; return true;
} }
template <typename PixelT, typename WeightT> template <typename PixelT, typename WeightT>
inline bool 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; return a > b;
} }
template <typename PixelT, typename WeightT> template <typename PixelT, typename WeightT>
inline bool 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); return isWeightInf (a.weight, b.weight);
} }
template <typename PixelT, typename WeightT> template <typename PixelT, typename WeightT>
inline void 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); 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> template <typename PixelT, typename WeightT>
inline inline
MaxWeight<PixelT, WeightT>::MaxWeight () MaxWeight<PixelT, WeightT>::MaxWeight ()
@ -182,6 +150,38 @@ MaxWeight<PixelT, WeightT>::getWeight (const DimImg &idx) const {
template <typename PixelT, typename WeightT> template <typename PixelT, typename WeightT>
inline WeightT inline WeightT
MaxWeight<PixelT, WeightT>::getWeight (const Point &a, const Point &b) const { 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)), return std::max (getWeight (WB::pointIdx (a)),
getWeight (WB::pointIdx (b))); getWeight (WB::pointIdx (b)));
} }

View File

@ -16,6 +16,9 @@ namespace otb {
inline PixelT *getValues (); inline PixelT *getValues ();
inline const PixelT *getValues () const; inline const PixelT *getValues () const;
template<typename WeightT>
inline void setValues (const PixelT *pixels, const WeightT *weights);
protected: protected:
const Tree &tree; const Tree &tree;
DimNodeId leafCount; DimNodeId leafCount;

View File

@ -1,6 +1,7 @@
#ifndef _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP #ifndef _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP
#define _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP #define _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP
// ========================================
template<typename PixelT> template<typename PixelT>
inline inline
AttributeProfiles<PixelT>::AttributeProfiles (const Tree &tree) AttributeProfiles<PixelT>::AttributeProfiles (const Tree &tree)
@ -34,6 +35,25 @@ AttributeProfiles<PixelT>::getValues () const {
return &values[0]; 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> template<typename PixelT>
inline void inline void
AttributeProfiles<PixelT>::free () { AttributeProfiles<PixelT>::free () {
@ -58,4 +78,5 @@ AttributeProfiles<PixelT>::print (ostream &out) const {
return out; return out;
} }
// ========================================
#endif // _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP #endif // _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP

View File

@ -9,7 +9,7 @@
namespace otb { namespace otb {
namespace triskele { namespace triskele {
class AreaAttributes : public CompAttributeC<DimImg> { class AreaAttributes : public CompAttribute<DimImg> {
public: public:
inline AreaAttributes (const Tree &tree); inline AreaAttributes (const Tree &tree);
inline ~AreaAttributes (); inline ~AreaAttributes ();

View File

@ -5,7 +5,7 @@ using namespace boost::chrono;
inline inline
AreaAttributes::AreaAttributes (const Tree &tree) AreaAttributes::AreaAttributes (const Tree &tree)
: CompAttributeC<DimImg> (tree) { : CompAttribute<DimImg> (tree) {
compute (); compute ();
} }
@ -18,7 +18,7 @@ inline void
AreaAttributes::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles, AreaAttributes::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
const vector<DimImg> &thresholds) const { const vector<DimImg> &thresholds) const {
auto start = high_resolution_clock::now (); 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 ()); globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
} }

View File

@ -11,11 +11,12 @@
namespace otb { namespace otb {
namespace triskele { namespace triskele {
class AverageAttributes : public CompAttributeC<double> { class AverageAttributes : public CompAttribute<double> {
public: public:
template<typename PixelT> template<typename PixelT>
inline AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes); inline AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes);
inline ~AverageAttributes (); inline ~AverageAttributes ();
virtual inline ostream &print (ostream &out) const { CompAttribute::print (out, "average"); return out; } virtual inline ostream &print (ostream &out) const { CompAttribute::print (out, "average"); return out; }
protected: protected:
template<typename PixelT> template<typename PixelT>

View File

@ -6,7 +6,7 @@ using namespace boost::chrono;
template<typename PixelT> template<typename PixelT>
inline inline
AverageAttributes::AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes) AverageAttributes::AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes)
: CompAttributeC<double> (tree) { : CompAttribute<double> (tree) {
compute (raster, areaAttributes); compute (raster, areaAttributes);
} }

View File

@ -9,7 +9,7 @@
namespace otb { namespace otb {
namespace triskele { namespace triskele {
class MoIAttributes : public CompAttributeC<double> { class MoIAttributes : public CompAttribute<double> {
public: public:
inline MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes); inline MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes);
inline ~MoIAttributes (); inline ~MoIAttributes ();

View File

@ -5,7 +5,7 @@ using namespace boost::chrono;
inline inline
MoIAttributes::MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes) MoIAttributes::MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes)
: CompAttributeC<double> (tree) { : CompAttribute<double> (tree) {
compute (areaAttributes, xyAttributes); compute (areaAttributes, xyAttributes);
} }
@ -23,8 +23,8 @@ MoIAttributes::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<P
auto start = high_resolution_clock::now (); auto start = high_resolution_clock::now ();
double maxValue = CompAttribute<double>::getMaxValue (); double maxValue = CompAttribute<double>::getMaxValue ();
cerr << "moi max value:" << maxValue << endl; cerr << "moi max value:" << maxValue << endl;
CompAttributeC<double>::cut (allBands, attributeProfiles, 0, CompAttribute<double>::cut (allBands, attributeProfiles, 0,
CompAttributeC<double>::getScaledThresholds (thresholds, maxValue)); CompAttribute<double>::getScaledThresholds (thresholds, maxValue));
globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ()); globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
} }

View File

@ -11,7 +11,7 @@
namespace otb { namespace otb {
namespace triskele { namespace triskele {
class SDAttributes : public CompAttributeC<double> { class SDAttributes : public CompAttribute<double> {
public: public:
inline SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes); inline SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes);
inline ~SDAttributes (); inline ~SDAttributes ();

View File

@ -5,7 +5,7 @@ using namespace boost::chrono;
inline inline
SDAttributes::SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes) SDAttributes::SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes)
: CompAttributeC<double> (tree) { : CompAttribute<double> (tree) {
compute (areaAttributes); compute (areaAttributes);
} }
@ -23,8 +23,8 @@ SDAttributes::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<Pi
auto start = high_resolution_clock::now (); auto start = high_resolution_clock::now ();
double maxValue = CompAttribute<double>::getMaxValue (); double maxValue = CompAttribute<double>::getMaxValue ();
cerr << "sd max value:" << maxValue << endl; cerr << "sd max value:" << maxValue << endl;
CompAttributeC<double>::cut (allBands, attributeProfiles, 0, CompAttribute<double>::cut (allBands, attributeProfiles, 0,
CompAttributeC<double>::getScaledThresholds (thresholds, maxValue)); CompAttribute<double>::getScaledThresholds (thresholds, maxValue));
globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ()); globalTreeStats.addTime (filteringStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
} }

View File

@ -2,6 +2,8 @@
#ifndef _OTB_TRISKELE_WEIGHT_ATTRIBUTES_HPP #ifndef _OTB_TRISKELE_WEIGHT_ATTRIBUTES_HPP
#define _OTB_TRISKELE_WEIGHT_ATTRIBUTES_HPP #define _OTB_TRISKELE_WEIGHT_ATTRIBUTES_HPP
#include <boost/chrono.hpp>
#include "triskeleBase.hpp" #include "triskeleBase.hpp"
namespace otb { namespace otb {
@ -15,6 +17,9 @@ namespace otb {
inline ~WeightAttributes (); inline ~WeightAttributes ();
inline void setWeightBounds (Tree &tree); 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; } virtual inline ostream &print (ostream &out) const { CompAttribute<WeightT>::print (out, "weight"); return out; }
}; };

View File

@ -1,6 +1,8 @@
#ifndef _OTB_TRISKELE_WEIGHT_ATTRIBUTES_TPP #ifndef _OTB_TRISKELE_WEIGHT_ATTRIBUTES_TPP
#define _OTB_TRISKELE_WEIGHT_ATTRIBUTES_TPP #define _OTB_TRISKELE_WEIGHT_ATTRIBUTES_TPP
using namespace boost::chrono;
template<typename WeightT> template<typename WeightT>
inline inline
WeightAttributes<WeightT>::WeightAttributes (const Tree &tree) WeightAttributes<WeightT>::WeightAttributes (const Tree &tree)
@ -39,4 +41,16 @@ WeightAttributes<WeightT>::setWeightBounds (Tree &tree) {
weightBounds.push_back (rootId+1); 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 #endif // _OTB_TRISKELE_WEIGHT_ATTRIBUTES_TPP

View File

@ -18,7 +18,7 @@ namespace otb {
operator DimImg () const { return (DimImg) (x*y); } operator DimImg () const { return (DimImg) (x*y); }
}; };
class XYAttributes : public CompAttributeC<AverageXY> { class XYAttributes : public CompAttribute<AverageXY> {
public: public:
inline XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes); inline XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes);
inline ~XYAttributes (); inline ~XYAttributes ();

View File

@ -5,7 +5,7 @@ using namespace boost::chrono;
inline inline
XYAttributes::XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes) XYAttributes::XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes)
: CompAttributeC<AverageXY> (tree) { : CompAttribute<AverageXY> (tree) {
compute (areaAttributes); compute (areaAttributes);
} }

View File

@ -14,6 +14,9 @@ namespace otb {
template<typename AttrT> template<typename AttrT>
class CompAttribute { class CompAttribute {
public: 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 (const Tree &tree);
inline ~CompAttribute (); inline ~CompAttribute ();
@ -22,6 +25,14 @@ namespace otb {
inline AttrT *getValues (); inline AttrT *getValues ();
inline AttrT getMaxValue () const; 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; } virtual inline ostream &print (ostream &out) const { print (out, ""); return out; }
protected: protected:
@ -32,39 +43,19 @@ namespace otb {
inline void free (); inline void free ();
inline void book (const DimImg &leafCount); 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; 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 } // triskele
} // otb } // otb
#include "Attributes/WeightAttributes.hpp" #include "Attributes/WeightAttributes.hpp"
namespace otb { namespace otb {
namespace triskele { 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" #include "CompAttribute.tpp"
} // triskele } // triskele
} // otb } // otb

View File

@ -1,6 +1,26 @@
#ifndef _OTB_TRISKELE_COMP_ATTRIBUTE_TPP #ifndef _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
#define _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> template<typename AttrT>
inline inline
CompAttribute<AttrT>::CompAttribute (const Tree &tree) CompAttribute<AttrT>::CompAttribute (const Tree &tree)
@ -47,78 +67,13 @@ CompAttribute<AttrT>::getMaxValue () const {
return max; 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 AttrT>
template<typename PixelT> template<typename PixelT>
inline void 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 { 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) { dealThreadRange (CompAttribute<AttrT>::leafCount, CompAttribute<AttrT>::tree.getCoreCount (), [this, &allBands, &attributeProfiles, &pixelAttrValue, &thresholds] (const DimImg &leafId) {
cutOnPos (allBands, attributeProfiles, leafId, pixelAttrValue, thresholds); cutOnPos (allBands, attributeProfiles, leafId, pixelAttrValue, thresholds);
}); });
@ -127,7 +82,7 @@ CompAttributeC<AttrT>::cut (vector<vector<PixelT> > &allBands, const AttributePr
template<typename AttrT> template<typename AttrT>
template<typename PixelT> template<typename PixelT>
inline void 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 { const DimImg &leafId, const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const {
// no debug (to many pixels) // no debug (to many pixels)
DimImg parentId = CompAttribute<AttrT>::tree.getLeafParent (leafId); DimImg parentId = CompAttribute<AttrT>::tree.getLeafParent (leafId);
@ -152,7 +107,7 @@ CompAttributeC<AttrT>::cutOnPos (vector<vector<PixelT> > &allBands, const Attrib
AttrT ceil = thresholds[chanel]; AttrT ceil = thresholds[chanel];
for ( ; curValue < ceil && curId < rootId; ) { for ( ; curValue < ceil && curId < rootId; ) {
if (parentId == DimImg_MAX || curId >= parentId) { 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) for (; chanel < thresholdsSize; ++chanel)
allBands[chanel][leafId] = curValue; allBands[chanel][leafId] = curValue;
return; 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 #endif // _OTB_TRISKELE_COMP_ATTRIBUTE_TPP

View File

@ -71,7 +71,7 @@ dealThread (const DimImg &maxId, unsigned int coreCount, const FunctThreadMinMax
functThreadMinMax (idCopyValInThread, maxIds[idCopyValInThread], maxIds[idCopyValInThread+1]); functThreadMinMax (idCopyValInThread, maxIds[idCopyValInThread], maxIds[idCopyValInThread+1]);
}); });
#else /* BOOST thread */ #else /* BOOST thread */
boost::thread tasks [coreCount]; std::vector<boost::thread> tasks;
for (unsigned int idCopyValInThread = 0; idCopyValInThread < coreCount; ++idCopyValInThread) { for (unsigned int idCopyValInThread = 0; idCopyValInThread < coreCount; ++idCopyValInThread) {
tasks.push_back (boost::thread ([/*no ref!!!*/idCopyValInThread, &maxIds, &functThreadMinMax] () { tasks.push_back (boost::thread ([/*no ref!!!*/idCopyValInThread, &maxIds, &functThreadMinMax] () {
functThreadMinMax (idCopyValInThread, maxIds[idCopyValInThread], maxIds[idCopyValInThread+1]); functThreadMinMax (idCopyValInThread, maxIds[idCopyValInThread], maxIds[idCopyValInThread+1]);
@ -106,37 +106,37 @@ callOnSortedSets (const std::vector<DimImg> &sizes,
// get min // get min
bool found = false; bool found = false;
DimImg minVectIdx = 0; DimImg minVectIdx = 0;
WeightT minWeight = 0; WeightT maxWeight = 0;
for (DimImg vectId = 0; vectId < size; ++vectId) { for (DimImg vectId = 0; vectId < size; ++vectId) {
if (!vectCounts [vectId]) if (!vectCounts [vectId])
continue; continue;
WeightT tmpWeight = getWeight (vectId, 0); WeightT tmpWeight = getWeight (vectId, 0);
if (found && !isWeightInf (tmpWeight, minWeight)) if (found && !isWeightInf (tmpWeight, maxWeight))
continue; continue;
minVectIdx = vectId; minVectIdx = vectId;
minWeight = tmpWeight; maxWeight = tmpWeight;
found = true; found = true;
} }
LOG ("found:" << found << " minVectIdx:" << minVectIdx << " minWeight:" << minWeight); LOG ("found:" << found << " minVectIdx:" << minVectIdx << " maxWeight:" << maxWeight);
// loop // loop
for ( ; found; ) { for ( ; found; ) {
// get next min // get next min
found = false; found = false;
DimImg nextMinVectIdx = 0; DimImg nextMinVectIdx = 0;
WeightT nextMinWeight = 0; WeightT nextMaxWeight = 0;
for (DimImg vectId = minVectIdx; ; ) { for (DimImg vectId = minVectIdx; ; ) {
if (vectCounts [vectId]) { if (vectCounts [vectId]) {
WeightT tmpWeight = getWeight (vectId, vectIds [vectId]); WeightT tmpWeight = getWeight (vectId, vectIds [vectId]);
if (!isWeightInf (minWeight, tmpWeight)) { if (!isWeightInf (maxWeight, tmpWeight)) {
// minWeight == tmpWeight // maxWeight == tmpWeight
callIdId (vectId, vectIds [vectId]); callIdId (vectId, vectIds [vectId]);
++vectIds [vectId]; ++vectIds [vectId];
--vectCounts [vectId]; --vectCounts [vectId];
continue; continue;
} }
if (!found || isWeightInf (tmpWeight, nextMinWeight)) { if (!found || isWeightInf (tmpWeight, nextMaxWeight)) {
nextMinVectIdx = vectId; nextMinVectIdx = vectId;
nextMinWeight = tmpWeight; nextMaxWeight = tmpWeight;
found = true; found = true;
} }
} }
@ -145,7 +145,7 @@ callOnSortedSets (const std::vector<DimImg> &sizes,
break; break;
} }
minVectIdx = nextMinVectIdx; minVectIdx = nextMinVectIdx;
minWeight = nextMinWeight; maxWeight = nextMaxWeight;
} }
} }

View File

@ -97,7 +97,7 @@ Option::parse (int argc, char** argv) {
bool helpFlag = false, versionFlag = false, useTheForceLuke = false; bool helpFlag = false, versionFlag = false, useTheForceLuke = false;
string inputFileName, outputFileName, bandsRange; string inputFileName, outputFileName, bandsRange;
long left = -1, top = -1, width = -1, height = -1; long left = -1, top = -1, width = -1, height = -1;
string areaThresholdsName, sdThresholdsName, moiThresholdsName; string areaThresholdsName, levelThresholdsName, sdThresholdsName, moiThresholdsName;
try { try {
desc.add_options () desc.add_options ()
("help", po::bool_switch (&helpFlag), "produce this help message") ("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)") ("height,h", po::value<long> (&height), "height crop (default input height)")
("input,i", po::value<string> (&inputFileName), "input file name image") ("input,i", po::value<string> (&inputFileName), "input file name image")
("output,o", po::value<string> (&outputFileName), "output file name hyperbands image (contains attributs profiles)") ("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") ("max-tree", po::bool_switch (&maxTreeFlag), "build max-tree")
("min-tree", po::bool_switch (&minTreeFlag), "build min-tree") ("min-tree", po::bool_switch (&minTreeFlag), "build min-tree")
("tos-tree", po::bool_switch (&tosTreeFlag), "build tree-of-shape") ("tos-tree", po::bool_switch (&tosTreeFlag), "build tree-of-shape")
("alpha-tree", po::bool_switch (&alphaTreeFlag), "build alpha-tree") ("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") ("area,A", po::value<string> (&areaThresholdsName), "produce area attributs")
("standard-deviation,S", po::value<string> (&sdThresholdsName), "produce standard deviation 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") ("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"); usage ("Bad options");
} }
areaThresholds = readThresholds<DimImg> (areaThresholdsName); areaThresholds = readThresholds<DimImg> (areaThresholdsName);
levelThresholds = readThresholds<double> (levelThresholdsName);
sdThresholds = readThresholds<double> (sdThresholdsName); sdThresholds = readThresholds<double> (sdThresholdsName);
moiThresholds = readThresholds<double> (moiThresholdsName); moiThresholds = readThresholds<double> (moiThresholdsName);

View File

@ -24,7 +24,7 @@ IImage::~IImage () {
void void
IImage::readImage () { 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 (gdalInputDataset == nullptr);
BOOST_ASSERT (gdalOutputDataset == nullptr); BOOST_ASSERT (gdalOutputDataset == nullptr);
close (); close ();

View File

@ -69,10 +69,10 @@ void apGenerator (Option &option) {
Border border (option.size, false); // default = no border Border border (option.size, false); // default = no border
GraphWalker graphWalker (border); GraphWalker graphWalker (border);
DimImg leafCount = graphWalker.vertexMaxCount (); 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)); 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) if (!option.oneBand)
option.outputImage.createImage (option.size, option.inputImage.getDataType (), outputBandsCard); option.outputImage.createImage (option.size, option.inputImage.getDataType (), outputBandsCard);
@ -88,9 +88,21 @@ void apGenerator (Option &option) {
WeightAttributes<PixelT> weightAttributes (tree); WeightAttributes<PixelT> weightAttributes (tree);
atb.buildTree (tree, weightAttributes); atb.buildTree (tree, weightAttributes);
AttributeProfiles<PixelT> attributeProfiles (tree); AttributeProfiles<PixelT> attributeProfiles (tree);
atb.setAttributProfiles (attributeProfiles);
AreaAttributes areaAttributes (tree); 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 ()) { if (option.areaThresholds.size ()) {
areaAttributes.cut (allBands, attributeProfiles, option.areaThresholds); areaAttributes.cut (allBands, attributeProfiles, option.areaThresholds);
for (DimChanel c = 0; c < option.areaThresholds.size (); ++c, ++chanel) for (DimChanel c = 0; c < option.areaThresholds.size (); ++c, ++chanel)