modifié : MakefileNoOTB
modifié : include/Appli/Option.hpp modifié : include/ArrayTree/ArrayTreeBuilder.hpp modifié : include/ArrayTree/ArrayTreeBuilder.tpp modifié : include/AttributeProfiles.hpp modifié : include/AttributeProfiles.tpp modifié : include/Attributes/AreaAttributes.hpp modifié : include/Attributes/AreaAttributes.tpp modifié : include/Attributes/MoIAttributes.hpp modifié : include/Attributes/MoIAttributes.tpp modifié : include/Attributes/SDAttributes.hpp modifié : include/Attributes/SDAttributes.tpp modifié : include/CompAttribute.hpp modifié : include/CompAttribute.tpp modifié : src/Appli/Option.cpp modifié : src/testMain.cpp
This commit is contained in:
parent
0388624f4b
commit
300bfd965d
@ -46,7 +46,7 @@ libtriskele: $(LIB_DIR)/libtriskele.a
|
|||||||
|
|
||||||
$(TST_OUT): $(TST_SRC) $(LIB_DIR)/libtriskele.a
|
$(TST_OUT): $(TST_SRC) $(LIB_DIR)/libtriskele.a
|
||||||
testMain: $(TST_OUT)
|
testMain: $(TST_OUT)
|
||||||
$(TST_OUT) data/nairobi-byte.tif data/result.tif -b 0 -w 5 -h 5 # --debug
|
$(TST_OUT) data/nairobi-byte.tif data/result.tif --debug -b 0 -w 4000 -h 4000 --min-tree -A data/areaThresholds.txt
|
||||||
|
|
||||||
## DEPENDS #############################
|
## DEPENDS #############################
|
||||||
ALL_OUT = $(TST_OUT)
|
ALL_OUT = $(TST_OUT)
|
||||||
|
@ -22,7 +22,10 @@ namespace otb {
|
|||||||
Point topLeft = NullPoint;
|
Point topLeft = NullPoint;
|
||||||
Size size = NullSize;
|
Size size = NullSize;
|
||||||
DimChanel chanel = 0;
|
DimChanel chanel = 0;
|
||||||
unsigned int treeCoreCount = boost::thread::hardware_concurrency ();
|
vector<DimImg> areaThresholds;
|
||||||
|
vector<double> sdThresholds, moiThresholds;
|
||||||
|
unsigned int coreCount = boost::thread::hardware_concurrency ();
|
||||||
|
bool maxTreeFlag = false, minTreeFlag = false, tosTreeFlag = false;
|
||||||
|
|
||||||
Option ();
|
Option ();
|
||||||
Option (int argc, char** argv);
|
Option (int argc, char** argv);
|
||||||
|
@ -40,7 +40,7 @@ namespace otb {
|
|||||||
inline ~ArrayTreeBuilder ();
|
inline ~ArrayTreeBuilder ();
|
||||||
|
|
||||||
inline void buildTree (Tree &tree, WeightAttributes<WeightT> &weightAttributes);
|
inline void buildTree (Tree &tree, WeightAttributes<WeightT> &weightAttributes);
|
||||||
inline void setAttributProfiles (AttributeProfiles<PixelT> &attributeProfiles, const Raster<PixelT> &raster);
|
inline void setAttributProfiles (AttributeProfiles<PixelT> &attributeProfiles);
|
||||||
protected:
|
protected:
|
||||||
template<typename WeightFunct>
|
template<typename WeightFunct>
|
||||||
inline void
|
inline void
|
||||||
|
@ -38,16 +38,17 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, WeightAttributes<Weigh
|
|||||||
compWeights = weightAttributes.getValues ();
|
compWeights = weightAttributes.getValues ();
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
// case MIN:
|
case MIN:
|
||||||
// buildTree (tree, MinWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
buildTree (tree, MinWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
||||||
break;
|
break;
|
||||||
case MAX:
|
case MAX:
|
||||||
buildTree (tree, MaxWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
buildTree (tree, MaxWeight<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));
|
||||||
break;
|
break;
|
||||||
// XXX msg
|
default:
|
||||||
|
cerr << "*** unknown tree type: " << type << endl;
|
||||||
}
|
}
|
||||||
weightAttributes.setWeightBounds (tree);
|
weightAttributes.setWeightBounds (tree);
|
||||||
leaders.free ();
|
leaders.free ();
|
||||||
@ -59,20 +60,21 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, WeightAttributes<Weigh
|
|||||||
// ========================================
|
// ========================================
|
||||||
template<typename WeightT, typename PixelT>
|
template<typename WeightT, typename PixelT>
|
||||||
inline void
|
inline void
|
||||||
ArrayTreeBuilder<WeightT, PixelT>::setAttributProfiles (AttributeProfiles<PixelT> &attributeProfiles, const Raster<PixelT> &raster) {
|
ArrayTreeBuilder<WeightT, PixelT>::setAttributProfiles (AttributeProfiles<PixelT> &attributeProfiles) {
|
||||||
DEF_LOG ("ArrayTreeBuilder::setAttributProfiles", "");
|
DEF_LOG ("ArrayTreeBuilder::setAttributProfiles", "");
|
||||||
attributeProfiles.updateTranscient ();
|
attributeProfiles.updateTranscient ();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
// case MIN:
|
case MIN:
|
||||||
// setAttributProfiles (attributeProfiles, MinWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
setAttributProfiles (attributeProfiles, MinWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
||||||
break;
|
break;
|
||||||
case MAX:
|
case MAX:
|
||||||
setAttributProfiles (attributeProfiles, MaxWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
setAttributProfiles (attributeProfiles, MaxWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
||||||
break;
|
break;
|
||||||
// case TOS:
|
case TOS:
|
||||||
// setAttributProfiles (attributeProfiles, MedianWeight<PixelT, WeightT> (raster.getPixels (), raster.getSize ()));
|
setAttributProfiles (attributeProfiles, MedianWeight<PixelT, WeightT> (raster.getPixels (), graphWalker));
|
||||||
break;
|
break;
|
||||||
// XXX msg
|
default:
|
||||||
|
cerr << "*** unknown tree type: " << type << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,9 +12,10 @@ namespace otb {
|
|||||||
inline AttributeProfiles (const Tree &tree);
|
inline AttributeProfiles (const Tree &tree);
|
||||||
inline ~AttributeProfiles ();
|
inline ~AttributeProfiles ();
|
||||||
|
|
||||||
inline void updateTranscient ();
|
inline void updateTranscient ();
|
||||||
inline PixelT *getValues ();
|
inline PixelT *getValues ();
|
||||||
inline void printValues () const;
|
inline const PixelT *getValues () const;
|
||||||
|
inline void printValues () const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const Tree &tree;
|
const Tree &tree;
|
||||||
|
@ -28,6 +28,12 @@ AttributeProfiles<PixelT>::getValues () {
|
|||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename PixelT>
|
||||||
|
inline const PixelT *
|
||||||
|
AttributeProfiles<PixelT>::getValues () const {
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
inline void
|
inline void
|
||||||
AttributeProfiles<PixelT>::printValues () const {
|
AttributeProfiles<PixelT>::printValues () const {
|
||||||
|
@ -11,6 +11,10 @@ namespace otb {
|
|||||||
public:
|
public:
|
||||||
inline AreaAttributes (const Tree &tree);
|
inline AreaAttributes (const Tree &tree);
|
||||||
inline ~AreaAttributes ();
|
inline ~AreaAttributes ();
|
||||||
|
|
||||||
|
template<typename PixelT>
|
||||||
|
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
|
const vector<DimImg> &thresholds) const;
|
||||||
protected:
|
protected:
|
||||||
inline void compute ();
|
inline void compute ();
|
||||||
};
|
};
|
||||||
|
@ -11,6 +11,13 @@ inline
|
|||||||
AreaAttributes::~AreaAttributes () {
|
AreaAttributes::~AreaAttributes () {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename PixelT>
|
||||||
|
inline void
|
||||||
|
AreaAttributes::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
|
const vector<DimImg> &thresholds) const {
|
||||||
|
CompAttributeC<DimImg>::cut (allBands, attributeProfiles, 1, thresholds);
|
||||||
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
AreaAttributes::compute () {
|
AreaAttributes::compute () {
|
||||||
computeSameCompLevel ([this] (const DimImg &parentId) {
|
computeSameCompLevel ([this] (const DimImg &parentId) {
|
||||||
|
@ -11,6 +11,10 @@ namespace otb {
|
|||||||
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 ();
|
||||||
|
|
||||||
|
template<typename PixelT>
|
||||||
|
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
|
const vector<double> &thresholds) const;
|
||||||
protected:
|
protected:
|
||||||
inline void compute (const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes);
|
inline void compute (const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes);
|
||||||
};
|
};
|
||||||
|
@ -11,6 +11,15 @@ inline
|
|||||||
MoIAttributes::~MoIAttributes () {
|
MoIAttributes::~MoIAttributes () {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename PixelT>
|
||||||
|
inline void
|
||||||
|
MoIAttributes::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
|
const vector<double> &thresholds) const {
|
||||||
|
DEF_LOG ("MoIAttributes::cut", "thresholds:" << thresholds.size ());
|
||||||
|
CompAttributeC<double>::cut (allBands, attributeProfiles, 0,
|
||||||
|
CompAttributeC<double>::getScaledThresholds (thresholds, CompAttribute<double>::getMaxValue ()));
|
||||||
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
MoIAttributes::compute (const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes) {
|
MoIAttributes::compute (const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes) {
|
||||||
const AverageXY *xy = xyAttributes.getValues ();
|
const AverageXY *xy = xyAttributes.getValues ();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef _OTB_TRISKELE_SD_ATTRIBUTES_HPP
|
#ifndef _OTB_TRISKELE_SD_ATTRIBUTES_HPP
|
||||||
#define _OTB_TRISKELE_SD_ATTRIBUTES_HPP
|
#define _OTB_TRISKELE_SD_ATTRIBUTES_HPP
|
||||||
|
|
||||||
|
#include "triskeleDebug.hpp"
|
||||||
#include "triskeleBase.hpp"
|
#include "triskeleBase.hpp"
|
||||||
#include "CompAttribute.hpp"
|
#include "CompAttribute.hpp"
|
||||||
#include "Attributes/AreaAttributes.hpp"
|
#include "Attributes/AreaAttributes.hpp"
|
||||||
@ -12,6 +13,10 @@ namespace otb {
|
|||||||
public:
|
public:
|
||||||
inline SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes);
|
inline SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes);
|
||||||
inline ~SDAttributes ();
|
inline ~SDAttributes ();
|
||||||
|
|
||||||
|
template<typename PixelT>
|
||||||
|
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
|
const vector<double> &thresholds) const;
|
||||||
protected:
|
protected:
|
||||||
inline void compute (const AreaAttributes &areaAttributes);
|
inline void compute (const AreaAttributes &areaAttributes);
|
||||||
};
|
};
|
||||||
|
@ -11,6 +11,15 @@ inline
|
|||||||
SDAttributes::~SDAttributes () {
|
SDAttributes::~SDAttributes () {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename PixelT>
|
||||||
|
inline void
|
||||||
|
SDAttributes::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
|
const vector<double> &thresholds) const {
|
||||||
|
DEF_LOG ("SDAttributes::cut", "thresholds:" << thresholds.size ());
|
||||||
|
CompAttributeC<double>::cut (allBands, attributeProfiles, 0,
|
||||||
|
CompAttributeC<double>::getScaledThresholds (thresholds, CompAttribute<double>::getMaxValue ()));
|
||||||
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
SDAttributes::compute (const AreaAttributes &areaAttributes) {
|
SDAttributes::compute (const AreaAttributes &areaAttributes) {
|
||||||
const DimImg *areas = areaAttributes.getValues ();
|
const DimImg *areas = areaAttributes.getValues ();
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "triskeleDebug.hpp"
|
||||||
#include "triskeleBase.hpp"
|
#include "triskeleBase.hpp"
|
||||||
#include "Tree.hpp"
|
#include "Tree.hpp"
|
||||||
#include "AttributeProfiles.hpp"
|
#include "AttributeProfiles.hpp"
|
||||||
@ -19,6 +20,7 @@ namespace otb {
|
|||||||
inline void updateTranscient ();
|
inline void updateTranscient ();
|
||||||
inline const AttrT *getValues () const;
|
inline const AttrT *getValues () const;
|
||||||
inline AttrT *getValues ();
|
inline AttrT *getValues ();
|
||||||
|
inline AttrT getMaxValue () const;
|
||||||
inline void printValues (const string &msg) const;
|
inline void printValues (const string &msg) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -38,30 +40,25 @@ namespace otb {
|
|||||||
namespace otb {
|
namespace otb {
|
||||||
namespace triskele {
|
namespace triskele {
|
||||||
|
|
||||||
template <typename AttrT>
|
|
||||||
struct ThresholdsChanel {
|
|
||||||
AttrT threshold;
|
|
||||||
DimChanel chanel;
|
|
||||||
ThresholdsChanel (const AttrT &threshold, const DimChanel &chanel) : threshold (threshold), chanel (chanel) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename AttrT>
|
template<typename AttrT>
|
||||||
class CompAttributeC : public CompAttribute<AttrT> {
|
class CompAttributeC : public CompAttribute<AttrT> {
|
||||||
public:
|
public:
|
||||||
inline CompAttributeC (const Tree &tree);
|
inline CompAttributeC (const Tree &tree);
|
||||||
inline ~CompAttributeC ();
|
inline ~CompAttributeC ();
|
||||||
|
|
||||||
|
static inline vector<AttrT> getScaledThresholds (const vector<double> &thresholds, const AttrT &maxValue);
|
||||||
|
|
||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
inline void cut (vector<vector<PixelT> > allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
const AttrT &pixelAttrValue, const vector<const ThresholdsChanel<AttrT> > &selection);
|
const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const;
|
||||||
|
|
||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
inline void cutOnPos (vector<vector<PixelT> > allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
inline void cutOnPos (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
const DimImg &pixelId, const AttrT &pixelAttrValue, const vector<const ThresholdsChanel<AttrT> > &selection);
|
const DimImg &pixelId, const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
template<typename CumpFunctPSE>
|
template<typename CumpFunctPSE>
|
||||||
inline void computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE /* cumpFunctPSE (DimImg parentId)*/);
|
inline void computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE /* cumpFunctPSE (DimImg parentId)*/) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "CompAttribute.tpp"
|
#include "CompAttribute.tpp"
|
||||||
|
@ -34,6 +34,18 @@ CompAttribute<AttrT>::getValues () {
|
|||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename AttrT>
|
||||||
|
inline AttrT
|
||||||
|
CompAttribute<AttrT>::getMaxValue () const {
|
||||||
|
if (!leafCount)
|
||||||
|
return 0;
|
||||||
|
AttrT max = values[0];
|
||||||
|
CompAttribute<AttrT>::tree.forEachComp ([this, &max] (const DimImg &compId) {
|
||||||
|
if (values[compId] > max)
|
||||||
|
max = values[compId];
|
||||||
|
});
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename AttrT>
|
template<typename AttrT>
|
||||||
inline void
|
inline void
|
||||||
@ -75,13 +87,25 @@ inline
|
|||||||
CompAttributeC<AttrT>::~CompAttributeC () {
|
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 AttrT>
|
||||||
template<typename CumpFunctPSE>
|
template<typename CumpFunctPSE>
|
||||||
inline void
|
inline void
|
||||||
CompAttributeC<AttrT>::computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE) {
|
CompAttributeC<AttrT>::computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE) const {
|
||||||
const vector<DimImg> &weightBounds (CompAttribute<AttrT>::tree.getWeightBounds ());
|
const vector<DimImg> &weightBounds (CompAttribute<AttrT>::tree.getWeightBounds ());
|
||||||
unsigned int coreCount = CompAttribute<AttrT>::tree.getCoreCount ();
|
unsigned int coreCount = CompAttribute<AttrT>::tree.getCoreCount ();
|
||||||
|
DEF_LOG ("CompAttributeC::computeSameCompLevel", "coreCount:" << coreCount);
|
||||||
if (!weightBounds.size () || CompAttribute<AttrT>::tree.getCompCount ()/weightBounds.size () < coreCount) {
|
if (!weightBounds.size () || CompAttribute<AttrT>::tree.getCompCount ()/weightBounds.size () < coreCount) {
|
||||||
|
LOG ("CompAttributeC::computeSameCompLevel: no thread");
|
||||||
CompAttribute<AttrT>::tree.forEachComp (cumpFunctPSE);
|
CompAttribute<AttrT>::tree.forEachComp (cumpFunctPSE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -99,51 +123,54 @@ CompAttributeC<AttrT>::computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE) {
|
|||||||
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,
|
CompAttributeC<AttrT>::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
const AttrT &pixelAttrValue, const vector<const ThresholdsChanel<AttrT> > &selection) {
|
const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const {
|
||||||
dealThreadRange (CompAttribute<AttrT>::leafCount, CompAttribute<AttrT>::coreCount, [this, &allBands, &attributeProfiles, &pixelAttrValue, &selection] (const DimImg &leafId) {
|
DEF_LOG ("CompAttributeC::cut", "coreCount:" << CompAttribute<AttrT>::tree.getCoreCount () << " thresholds:" << thresholds.size ());
|
||||||
cutOnPos (allBands, attributeProfiles, leafId, pixelAttrValue, selection);
|
dealThreadRange (CompAttribute<AttrT>::leafCount, CompAttribute<AttrT>::tree.getCoreCount (), [this, &allBands, &attributeProfiles, &pixelAttrValue, &thresholds] (const DimImg &leafId) {
|
||||||
|
cutOnPos (allBands, attributeProfiles, leafId, pixelAttrValue, thresholds);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
CompAttributeC<AttrT>::cutOnPos (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
const DimImg &leafId, const AttrT &pixelAttrValue, const vector<const ThresholdsChanel<AttrT> > &selection) {
|
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.getLeafParents (leafId);
|
DimImg parentId = CompAttribute<AttrT>::tree.getLeafParent (leafId);
|
||||||
DimChanel selectionSize = selection.size ();
|
DimChanel thresholdsSize = thresholds.size ();
|
||||||
if (parentId == DimImg_MAX) {
|
if (parentId == DimImg_MAX) {
|
||||||
for (DimChanel i = 0; i < selectionSize; ++i)
|
for (DimChanel chanel = 0; chanel < thresholdsSize; ++chanel)
|
||||||
allBands[leafId][selection[i].chanel] = 0;
|
allBands[chanel][leafId] = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DimNodeId nodeId = leafId, curId = 0;
|
DimNodeId nodeId = leafId;
|
||||||
|
DimImg curId = 0;
|
||||||
AttrT curValue = pixelAttrValue;
|
AttrT curValue = pixelAttrValue;
|
||||||
if (curValue == CompAttribute<AttrT>::values [parentId]) {
|
if (curValue == CompAttribute<AttrT>::values [parentId]) {
|
||||||
// skip pixel on flat zone
|
// skip pixel on flat zone
|
||||||
curId = parentId;
|
curId = parentId;
|
||||||
nodeId = curId+CompAttribute<AttrT>::leafCount;
|
nodeId = ((DimNodeId)curId)+CompAttribute<AttrT>::leafCount;
|
||||||
parentId = CompAttribute<AttrT>::tree.getCompParent (curId);
|
parentId = CompAttribute<AttrT>::tree.getCompParent (curId);
|
||||||
}
|
}
|
||||||
|
const PixelT *apValues = attributeProfiles.getValues ();
|
||||||
DimImg rootId = CompAttribute<AttrT>::tree.getCompRoot ();
|
DimImg rootId = CompAttribute<AttrT>::tree.getCompRoot ();
|
||||||
for (DimChanel i = 0; i < selectionSize; ++i) {
|
for (DimChanel chanel = 0; chanel < thresholdsSize; ++chanel) {
|
||||||
AttrT ceil = selection[i].threshold;
|
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) {
|
||||||
// XXX root
|
// cerr << "CompAttributeC::cutOnPos find sub-root:" << rootId << " rootId:" << rootId << endl;
|
||||||
for (; i < selectionSize; ++i)
|
for (; chanel < thresholdsSize; ++chanel)
|
||||||
allBands[leafId][selection[i].chanel] = 0;
|
allBands[chanel][leafId] = curValue;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
nodeId = CompAttribute<AttrT>::tree.getLeafParents (nodeId)+CompAttribute<AttrT>::leafCount;
|
nodeId = ((DimNodeId) CompAttribute<AttrT>::tree.getLeafParent (nodeId))+CompAttribute<AttrT>::leafCount;
|
||||||
curId = parentId;
|
curId = parentId;
|
||||||
curValue = CompAttribute<AttrT>::values [curId];
|
curValue = CompAttribute<AttrT>::values [curId];
|
||||||
parentId = CompAttribute<AttrT>::tree.getCompParents (curId);
|
parentId = CompAttribute<AttrT>::tree.getCompParent (curId);
|
||||||
}
|
}
|
||||||
// XXX si valeur > root ?
|
// XXX si valeur > root ?
|
||||||
allBands[leafId][selection[i].chanel] = attributeProfiles [nodeId];
|
allBands[chanel][leafId] = apValues [nodeId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <boost/program_options/options_description.hpp>
|
#include <boost/program_options/options_description.hpp>
|
||||||
#include <boost/program_options/variables_map.hpp>
|
#include <boost/program_options/variables_map.hpp>
|
||||||
#include <boost/program_options/parsers.hpp>
|
#include <boost/program_options/parsers.hpp>
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#include "triskeleDebug.hpp"
|
#include "triskeleDebug.hpp"
|
||||||
#include "triskeleBase.hpp"
|
#include "triskeleBase.hpp"
|
||||||
@ -18,9 +19,36 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
using namespace boost::filesystem;
|
||||||
|
|
||||||
using namespace triskele;
|
using namespace triskele;
|
||||||
using namespace otb::triskele;
|
using namespace otb::triskele;
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
template<typename T>
|
||||||
|
vector<T>
|
||||||
|
readThresholds (string fileName) {
|
||||||
|
vector<T> thresholds;
|
||||||
|
if (fileName.empty ()) {
|
||||||
|
return thresholds;
|
||||||
|
}
|
||||||
|
std::ifstream ifs;
|
||||||
|
ifs.open (fileName);
|
||||||
|
string line;
|
||||||
|
while (getline (ifs, line)) {
|
||||||
|
stringstream ss (line);
|
||||||
|
T value;
|
||||||
|
ss >> value;
|
||||||
|
if (ss.fail ())
|
||||||
|
continue;
|
||||||
|
thresholds.push_back (value);
|
||||||
|
}
|
||||||
|
if (!thresholds.size ())
|
||||||
|
cerr << "*** readThresholds: empty file: " << fileName << endl;
|
||||||
|
sort (thresholds.begin (), thresholds.end ());
|
||||||
|
return thresholds;
|
||||||
|
}
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
Option::Option () {
|
Option::Option () {
|
||||||
}
|
}
|
||||||
@ -69,6 +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;
|
string inputFileName, outputFileName;
|
||||||
long left = -1, top = -1, width = -1, height = -1;
|
long left = -1, top = -1, width = -1, height = -1;
|
||||||
|
string areaThresholdsName, 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")
|
||||||
@ -82,14 +111,16 @@ 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)")
|
||||||
//("min-tree", po::bool_switch (&options.noTreeFlag[minE]), "build min-tree")
|
("max-tree", po::bool_switch (&maxTreeFlag), "build max-tree")
|
||||||
//("area,A", po::value<string> (&areaThresholdsName), "produce area attributs")
|
("min-tree", po::bool_switch (&minTreeFlag), "build min-tree")
|
||||||
;
|
("tos-tree", po::bool_switch (&tosTreeFlag), "build tree-of-shape")
|
||||||
|
("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")
|
||||||
|
;
|
||||||
hide.add_options ()
|
hide.add_options ()
|
||||||
("use-the-force-luke", po::bool_switch (&useTheForceLuke), "display hidded options")
|
("use-the-force-luke", po::bool_switch (&useTheForceLuke), "display hidded options")
|
||||||
("tree-core-count", po::value<unsigned int> (&treeCoreCount), "thread used to build tree (default hardware value)")
|
("tree-core-count", po::value<unsigned int> (&coreCount), "thread used to build tree (default hardware value)")
|
||||||
// ("max-tree", po::bool_switch (&options.noTreeFlag[maxE]), "build max-tree")
|
|
||||||
// ("tos-tree", po::bool_switch (&options.noTreeFlag[tosE]), "build tree-of-shape")
|
|
||||||
// ("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,I", po::value<string> (&moiThresholdsName), "produce moment of inertia attributs")
|
// ("moment-of-inertia,I", po::value<string> (&moiThresholdsName), "produce moment of inertia attributs")
|
||||||
// ("no-border", po::bool_switch (&options.noBorder), "build tree with all pixels (included no-data)")
|
// ("no-border", po::bool_switch (&options.noBorder), "build tree with all pixels (included no-data)")
|
||||||
@ -111,7 +142,6 @@ Option::parse (int argc, char** argv) {
|
|||||||
p.add (inputFileC, -1);
|
p.add (inputFileC, -1);
|
||||||
po::variables_map vm;
|
po::variables_map vm;
|
||||||
po::store (po::command_line_parser (argc, argv).options (cmd).positional (p).run (), vm);
|
po::store (po::command_line_parser (argc, argv).options (cmd).positional (p).run (), vm);
|
||||||
po::store (po::command_line_parser (argc, argv).options (desc).positional (p).run (), vm);
|
|
||||||
po::notify (vm);
|
po::notify (vm);
|
||||||
|
|
||||||
if (useTheForceLuke)
|
if (useTheForceLuke)
|
||||||
@ -150,6 +180,10 @@ Option::parse (int argc, char** argv) {
|
|||||||
} catch (...) {
|
} catch (...) {
|
||||||
usage ("Bad options");
|
usage ("Bad options");
|
||||||
}
|
}
|
||||||
|
areaThresholds = readThresholds<DimImg> (areaThresholdsName);
|
||||||
|
sdThresholds = readThresholds<double> (sdThresholdsName);
|
||||||
|
moiThresholds = readThresholds<double> (moiThresholdsName);
|
||||||
|
|
||||||
inputImage.setFileName (inputFileName);
|
inputImage.setFileName (inputFileName);
|
||||||
outputImage.setFileName (outputFileName);
|
outputImage.setFileName (outputFileName);
|
||||||
inputImage.readImage ();
|
inputImage.readImage ();
|
||||||
|
108
src/testMain.cpp
108
src/testMain.cpp
@ -32,47 +32,74 @@ using namespace otb::triskele::arrayTree;
|
|||||||
|
|
||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
inline
|
inline
|
||||||
void prog (Option &option) {
|
void apGenerator (Option &option) {
|
||||||
Raster<PixelT> raster;
|
|
||||||
option.inputImage.readBand (raster, option.chanel, option.topLeft, option.size);
|
vector<TreeType> treeTypes;
|
||||||
|
if (option.minTreeFlag)
|
||||||
|
treeTypes.push_back (MIN);
|
||||||
|
if (option.maxTreeFlag)
|
||||||
|
treeTypes.push_back (MAX);
|
||||||
|
if (option.tosTreeFlag)
|
||||||
|
treeTypes.push_back (TOS);
|
||||||
|
DimChanel treeTypesCard = treeTypes.size ();
|
||||||
|
if (!treeTypesCard)
|
||||||
|
cerr << "*** no tree type ! => copy mode" << endl;
|
||||||
|
|
||||||
Border border; // default = no border
|
Border border; // default = no border
|
||||||
GraphWalker graphWalker (raster.getSize (), border);
|
GraphWalker graphWalker (option.size, border);
|
||||||
ArrayTreeBuilder<PixelT, PixelT> atb (raster, graphWalker, TreeType::MAX);
|
DimImg leafCount = graphWalker.vertexMaxCount ();
|
||||||
Tree tree (option.treeCoreCount);
|
DimChanel maxThresholds = max (max (option.areaThresholds.size (), option.sdThresholds.size ()), option.moiThresholds.size ());
|
||||||
WeightAttributes<PixelT> weightAttributes (tree);
|
vector <vector <PixelT> > allBands (maxThresholds, vector<PixelT> (leafCount, 0));
|
||||||
atb.buildTree (tree, weightAttributes);
|
|
||||||
weightAttributes.printValues ("weight");
|
|
||||||
|
|
||||||
tree.printTree ();
|
DimChanel outputBandsCard = 1+treeTypesCard*(option.areaThresholds.size ()+option.sdThresholds.size ()+option.moiThresholds.size ()); // XXX * bands
|
||||||
|
option.outputImage.createImage (option.size, option.inputImage.getDataType (), outputBandsCard);
|
||||||
|
|
||||||
AttributeProfiles<PixelT> attributeProfiles (tree);
|
Raster<PixelT> raster;
|
||||||
atb.setAttributProfiles (attributeProfiles, raster);
|
DimChanel chanel = 0;
|
||||||
attributeProfiles.printValues ();
|
// XXX band loop
|
||||||
|
DimChanel band = option.chanel;
|
||||||
|
option.inputImage.readBand (raster, band, option.topLeft, option.size);
|
||||||
|
option.outputImage.writeBand (raster.getPixels (), chanel++);
|
||||||
|
|
||||||
AreaAttributes areaAttributes (tree);
|
for (TreeType treeType : treeTypes) {
|
||||||
areaAttributes.printValues ("area");
|
ArrayTreeBuilder<PixelT, PixelT> atb (raster, graphWalker, treeType);
|
||||||
AverageAttributes averageAttributes (tree, raster, areaAttributes);
|
Tree tree (option.coreCount);
|
||||||
averageAttributes.printValues ("average");
|
WeightAttributes<PixelT> weightAttributes (tree);
|
||||||
SDAttributes sdAttributes (tree, areaAttributes);
|
atb.buildTree (tree, weightAttributes);
|
||||||
sdAttributes.printValues ("sd");
|
AttributeProfiles<PixelT> attributeProfiles (tree);
|
||||||
XYAttributes xyAttributes (tree, areaAttributes);
|
atb.setAttributProfiles (attributeProfiles);
|
||||||
//xyAttributes.printValues ("XY"); // pb print de complexe
|
|
||||||
MoIAttributes moiAttributes (tree, areaAttributes, xyAttributes);
|
|
||||||
moiAttributes.printValues ("moi");
|
|
||||||
|
|
||||||
// XXX cut allProfiles.clear ();
|
AreaAttributes areaAttributes (tree);
|
||||||
DimChanel nbBands = 1;
|
areaAttributes.cut (allBands, attributeProfiles, option.areaThresholds);
|
||||||
vector <vector <PixelT> > allBands (tree.getLeafCount (), vector<PixelT> (nbBands, 0));
|
for (DimChanel c = 0; c < option.areaThresholds.size (); ++c, ++chanel)
|
||||||
|
option.outputImage.writeBand (&allBands[c][0], chanel);
|
||||||
|
|
||||||
// attribute.cut (out, attributProfiles, threshold)
|
{ // free SDAttributes after use
|
||||||
|
SDAttributes sdAttributes (tree, areaAttributes);
|
||||||
|
sdAttributes.cut (allBands, attributeProfiles, option.sdThresholds);
|
||||||
|
for (DimChanel c = 0; c < option.sdThresholds.size (); ++c, ++chanel)
|
||||||
|
option.outputImage.writeBand (&allBands[c][0], chanel);
|
||||||
|
}
|
||||||
|
{ // free MoIAttributes after use
|
||||||
|
XYAttributes xyAttributes (tree, areaAttributes);
|
||||||
|
MoIAttributes moiAttributes (tree, areaAttributes, xyAttributes);
|
||||||
|
moiAttributes.cut (allBands, attributeProfiles, option.moiThresholds);
|
||||||
|
for (DimChanel c = 0; c < option.moiThresholds.size (); ++c, ++chanel)
|
||||||
|
option.outputImage.writeBand (&allBands[c][0], chanel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// XXX write
|
//weightAttributes.printValues ("weight");
|
||||||
option.outputImage.createImage (tree.getSize (), option.inputImage.getDataType (), nbBands);
|
//tree.printTree ();
|
||||||
for (DimChanel c = 0; c < nbBands; ++c)
|
//attributeProfiles.printValues ();
|
||||||
option.outputImage.writeBand (&allBands[c][0], c);
|
//areaAttributes.printValues ("area");
|
||||||
|
// AverageAttributes averageAttributes (tree, raster, areaAttributes);
|
||||||
|
// averageAttributes.printValues ("average");
|
||||||
|
// sdAttributes.printValues ("sd");
|
||||||
|
// //xyAttributes.printValues ("XY"); // pb print de complexe
|
||||||
|
// moiAttributes.printValues ("moi");
|
||||||
|
|
||||||
cerr << endl << "*** prog ok!" << endl;
|
cerr << endl << "*** apGenerator done!" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -82,20 +109,21 @@ main (int argc, char** argv, char** envp) {
|
|||||||
|
|
||||||
switch (option.inputImage.getDataType ()) {
|
switch (option.inputImage.getDataType ()) {
|
||||||
case GDT_Byte:
|
case GDT_Byte:
|
||||||
prog<uint8_t> (option); break;
|
apGenerator<uint8_t> (option); break;
|
||||||
|
|
||||||
// case GDT_UInt16:
|
// case GDT_UInt16:
|
||||||
// prog<uint16_t> (option); break;
|
// apGenerator<uint16_t> (option); break;
|
||||||
// case GDT_Int16:
|
// case GDT_Int16:
|
||||||
// prog<int16_t> (option); break;
|
// apGenerator<int16_t> (option); break;
|
||||||
// case GDT_UInt32:
|
// case GDT_UInt32:
|
||||||
// prog<uint32_t> (option); break;
|
// apGenerator<uint32_t> (option); break;
|
||||||
// case GDT_Int32:
|
// case GDT_Int32:
|
||||||
// prog<int32_t> (option); break;
|
// apGenerator<int32_t> (option); break;
|
||||||
// case GDT_Float32:
|
// case GDT_Float32:
|
||||||
// prog<float> (option); break;
|
// apGenerator<float> (option); break;
|
||||||
// case GDT_Float64:
|
// case GDT_Float64:
|
||||||
// prog<double> (option); break;
|
// apGenerator<double> (option); break;
|
||||||
|
|
||||||
default :
|
default :
|
||||||
cerr << "unknown type!" << endl; break;
|
cerr << "unknown type!" << endl; break;
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user