
modifié : include/Attributes/AreaAttributes.hpp modifié : include/Attributes/AreaAttributes.tpp modifié : include/Attributes/AverageAttributes.hpp modifié : include/Attributes/AverageAttributes.tpp modifié : include/Attributes/MoIAttributes.hpp modifié : include/Attributes/MoIAttributes.tpp modifié : include/Attributes/SDAttributes.hpp modifié : include/Attributes/SDAttributes.tpp modifié : include/Attributes/WeightAttributes.hpp modifié : include/Attributes/WeightAttributes.tpp modifié : include/Attributes/XYAttributes.hpp modifié : include/Attributes/XYAttributes.tpp modifié : include/CompAttribute.hpp modifié : include/CompAttribute.tpp modifié : include/triskeleDealThreads.tpp modifié : src/Appli/Option.cpp modifié : src/IImage.cpp modifié : src/apGenerator.cpp
154 lines
5.5 KiB
C++
154 lines
5.5 KiB
C++
#include <iostream>
|
|
#include <boost/filesystem.hpp>
|
|
|
|
#include "triskeleDebug.hpp"
|
|
#include "triskeleBase.hpp"
|
|
#include "Appli/Option.hpp"
|
|
#include "Tree.hpp"
|
|
#include "TreeStats.hpp"
|
|
#include "TreeBuilder.hpp"
|
|
#include "QuadTree/QuadTreeBuilder.hpp"
|
|
//#include "XMLTree/XMLTreeBuilder.hpp"
|
|
#include "IImage.hpp"
|
|
|
|
#include "ArrayTree/triskeleArrayTreeBase.hpp"
|
|
#include "ArrayTree/triskeleSort.hpp"
|
|
#include "ArrayTree/Border.hpp"
|
|
#include "ArrayTree/GraphWalker.hpp"
|
|
#include "ArrayTree/Leader.hpp"
|
|
#include "ArrayTree/Weight.hpp"
|
|
|
|
#include "ArrayTree/ArrayTreeBuilder.hpp"
|
|
#include "Attributes/WeightAttributes.hpp"
|
|
#include "AttributeProfiles.hpp"
|
|
#include "Attributes/AreaAttributes.hpp"
|
|
#include "Attributes/AverageAttributes.hpp"
|
|
#include "Attributes/SDAttributes.hpp"
|
|
#include "Attributes/XYAttributes.hpp"
|
|
#include "Attributes/MoIAttributes.hpp"
|
|
|
|
//using namespace triskele;
|
|
using namespace otb::triskele;
|
|
using namespace otb::triskele::arrayTree;
|
|
|
|
template<typename PixelT>
|
|
inline void
|
|
writeBand (Option &option, PixelT *pixels, DimChanel band) {
|
|
if (!option.oneBand) {
|
|
option.outputImage.writeBand (pixels, band);
|
|
return;
|
|
}
|
|
string outputBaseName = boost::filesystem::path (option.outputImage.getFileName ()).replace_extension ("").string ();
|
|
string outputExtension = boost::filesystem::extension (option.outputImage.getFileName ());
|
|
|
|
ostringstream fileNameStream;
|
|
fileNameStream << outputBaseName << "-" << std::setfill ('0') << std::setw (3) << (band) << outputExtension;
|
|
IImage outputImage (fileNameStream.str ());
|
|
outputImage.createImage (option.size, option.inputImage.getDataType (), 1);
|
|
outputImage.writeBand (pixels, 0);
|
|
}
|
|
|
|
|
|
template<typename PixelT>
|
|
inline
|
|
void apGenerator (Option &option) {
|
|
|
|
vector<TreeType> treeTypes;
|
|
if (option.minTreeFlag)
|
|
treeTypes.push_back (MIN);
|
|
if (option.maxTreeFlag)
|
|
treeTypes.push_back (MAX);
|
|
if (option.tosTreeFlag)
|
|
treeTypes.push_back (TOS);
|
|
if (option.alphaTreeFlag)
|
|
treeTypes.push_back (ALPHA);
|
|
DimChanel treeTypesCard = treeTypes.size ();
|
|
if (!treeTypesCard)
|
|
cerr << "*** no tree type ! => copy mode" << endl;
|
|
|
|
Border border (option.size, false); // default = no border
|
|
GraphWalker graphWalker (border);
|
|
DimImg leafCount = graphWalker.vertexMaxCount ();
|
|
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.levelThresholds.size ()+option.sdThresholds.size ()+option.moiThresholds.size ()));
|
|
if (!option.oneBand)
|
|
option.outputImage.createImage (option.size, option.inputImage.getDataType (), outputBandsCard);
|
|
|
|
Raster<PixelT> raster;
|
|
DimChanel chanel = 0;
|
|
for (DimChanel band : option.selectedBand.getSet ()) {
|
|
option.inputImage.readBand (raster, band, option.topLeft, option.size);
|
|
writeBand (option, raster.getPixels (), chanel++);
|
|
|
|
for (TreeType treeType : treeTypes) {
|
|
ArrayTreeBuilder<PixelT, PixelT> atb (raster, graphWalker, treeType, option.countingSortCeil);
|
|
Tree tree (option.coreCount);
|
|
WeightAttributes<PixelT> weightAttributes (tree);
|
|
atb.buildTree (tree, weightAttributes);
|
|
AttributeProfiles<PixelT> attributeProfiles (tree);
|
|
atb.setAttributProfiles (attributeProfiles);
|
|
|
|
AreaAttributes areaAttributes (tree);
|
|
if (option.areaThresholds.size ()) {
|
|
areaAttributes.cut (allBands, attributeProfiles, option.areaThresholds);
|
|
for (DimChanel c = 0; c < option.areaThresholds.size (); ++c, ++chanel)
|
|
writeBand (option, &allBands[c][0], chanel);
|
|
}
|
|
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.sdThresholds.size ()) {
|
|
SDAttributes sdAttributes (tree, areaAttributes);
|
|
sdAttributes.cut (allBands, attributeProfiles, option.sdThresholds);
|
|
for (DimChanel c = 0; c < option.sdThresholds.size (); ++c, ++chanel)
|
|
writeBand (option, &allBands[c][0], chanel);
|
|
}
|
|
if (option.moiThresholds.size ()) {
|
|
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)
|
|
writeBand (option, &allBands[c][0], chanel);
|
|
}
|
|
}
|
|
}
|
|
|
|
cerr << endl << "*** apGenerator done!" << endl
|
|
<< globalTreeStats.printDim () << endl
|
|
<< globalTreeStats.printTime ();
|
|
}
|
|
|
|
int
|
|
main (int argc, char** argv, char** envp) {
|
|
Option option (argc, argv);
|
|
DEF_LOG ("main", "");
|
|
|
|
switch (option.inputImage.getDataType ()) {
|
|
case GDT_Byte:
|
|
apGenerator<uint8_t> (option); break;
|
|
|
|
case GDT_UInt16:
|
|
apGenerator<uint16_t> (option); break;
|
|
case GDT_Int16:
|
|
apGenerator<int16_t> (option); break;
|
|
case GDT_UInt32:
|
|
apGenerator<uint32_t> (option); break;
|
|
case GDT_Int32:
|
|
apGenerator<int32_t> (option); break;
|
|
case GDT_Float32:
|
|
apGenerator<float> (option); break;
|
|
case GDT_Float64:
|
|
apGenerator<double> (option); break;
|
|
|
|
default :
|
|
cerr << "unknown type!" << endl; break;
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|