Commit aa288e4d authored by remicres's avatar remicres
Browse files

REFAC: KWStyle

parent a34732ef
......@@ -10,7 +10,7 @@
#include "itkFixedArray.h"
#include "itkImageSource.h"
// GRM
// LSGRM
#include <iostream>
#include "lsgrmBaatzSegmenter.h"
#include "lsgrmSpringSegmenter.h"
......@@ -44,9 +44,6 @@ public:
typedef lsgrm::BaatzSegmenter<ImageType> BaatzSegmenterType;
typedef lsgrm::SpringSegmenter<ImageType> SpringSegmenterType;
typedef lsgrm::FullLambdaScheduleSegmenter<ImageType> FLSSegmenterType;
typedef lsgrm::Controller<BaatzSegmenterType> BaatzControllerType;
typedef lsgrm::Controller<SpringSegmenterType> SpringControllerType;
typedef lsgrm::Controller<FLSSegmenterType> FLSControllerType;
private:
......@@ -69,8 +66,8 @@ private:
void DoInit()
{
SetName("GenericRegionMerging");
SetDescription("This application allows to use the Generic Region Merging library "
"(GRM) and provides currently 3 homogeneity criteria: Euclidean Distance, "
SetDescription("This application allows to use the Large Scale Generic Region Merging library "
"(LSGRM) and provides currently 3 homogeneity criteria: Euclidean Distance, "
"Full Lambda Schedule and Baatz & Schape criterion.");
// Input and Output images
......@@ -114,7 +111,6 @@ private:
{
}
/*
* Return a prefix for temporary files
*/
......@@ -143,9 +139,16 @@ private:
/*
* This function sets the generic parameters of a controller and runs the segmentation
*/
template<class TController>
UInt32ImageType::Pointer SetGenericParametersAndRunSegmentation(typename TController::Pointer& controller)
{
template<class TSegmenter>
UInt32ImageType::Pointer SetGenericParametersAndRunSegmentation(const typename TSegmenter::ParamType params){
// Instantiate the controller
typedef typename lsgrm::Controller<TSegmenter> ControlerType;
typename ControlerType::Pointer controller = ControlerType::New();
// Set specific parameters
controller->SetSpecificParameters(params);
// Set input image
controller->SetInputImage(GetParameterFloatVectorImage("in"));
......@@ -195,8 +198,6 @@ private:
return controller->GetLabeledClusteredOutput();
}
void DoExecute()
{
/*
......@@ -214,33 +215,20 @@ private:
int inputCriterion = GetParameterInt("criterion");
if (inputCriterion == CRITERION_BAATZ)
{
// Baatz controller
BaatzControllerType::Pointer baatzController = BaatzControllerType::New();
// Specific parameters
grm::BaatzParam params;
params.m_SpectralWeight = GetParameterFloat("criterion.bs.cw");
params.m_ShapeWeight = GetParameterFloat("criterion.bs.sw");
baatzController->SetSpecificParameters(params);
// Run segmentation
labelImage = SetGenericParametersAndRunSegmentation<BaatzControllerType>(baatzController);
labelImage = SetGenericParametersAndRunSegmentation<BaatzSegmenterType>(params);
}
else if (inputCriterion == CRITERION_SPRING)
{
// Spring controller
SpringControllerType::Pointer springController = SpringControllerType::New();
// Run segmentation
labelImage = SetGenericParametersAndRunSegmentation<SpringControllerType>(springController);
grm::SpringParam params;
labelImage = SetGenericParametersAndRunSegmentation<SpringSegmenterType>(params);
}
else if (inputCriterion == CRITERION_FLS)
{
// Full Lambda Schedule (FLS) controller
FLSControllerType::Pointer flsController = FLSControllerType::New();
// Run segmentation
labelImage = SetGenericParametersAndRunSegmentation<FLSControllerType>(flsController);
grm::FLSParam params;
labelImage = SetGenericParametersAndRunSegmentation<FLSSegmenterType>(params);
}
else
{
......@@ -253,7 +241,6 @@ private:
labelImage->SetSpacing(inputImage->GetSpacing());
SetParameterOutputImage<UInt32ImageType>("out", labelImage);
}
void AfterExecuteAndWriteOutputs()
......@@ -275,6 +262,4 @@ private:
} // end of namespace wrapper
} // end of namespace otb
OTB_APPLICATION_EXPORT(otb::Wrapper::LSGRM)
......@@ -6,10 +6,10 @@
namespace lsgrm
{
template<class TImage>
void
BaatzSegmenter<TImage>::WriteSpecificAttributes(NodePointerType node, FILE * nodeStream)
{
template<class TImage>
void
BaatzSegmenter<TImage>::WriteSpecificAttributes(NodePointerType node, FILE * nodeStream)
{
std::size_t bands = node->m_Means.size();
fwrite(&(bands), sizeof(bands), 1, nodeStream);
......@@ -20,12 +20,12 @@ namespace lsgrm
fwrite(&(node->m_SpectralSum[b]), sizeof(node->m_SpectralSum[b]), 1, nodeStream);
fwrite(&(node->m_Std[b]), sizeof(node->m_Std[b]), 1, nodeStream);
}
}
}
template<class TImage>
void
BaatzSegmenter<TImage>::ReadSpecificAttributes(NodePointerType node, FILE * nodeStream)
{
template<class TImage>
void
BaatzSegmenter<TImage>::ReadSpecificAttributes(NodePointerType node, FILE * nodeStream)
{
std::size_t bands;
fread(&(bands), sizeof(bands), 1, nodeStream);
node->m_Means.assign(bands, 0);
......@@ -40,12 +40,12 @@ namespace lsgrm
fread(&(node->m_SpectralSum[b]), sizeof(node->m_SpectralSum[b]), 1, nodeStream);
fread(&(node->m_Std[b]), sizeof(node->m_Std[b]), 1, nodeStream);
}
}
}
template<class TImage>
long long unsigned int
BaatzSegmenter<TImage>::GetNodeMemory(NodePointerType &node)
{
template<class TImage>
long long unsigned int
BaatzSegmenter<TImage>::GetNodeMemory(NodePointerType &node)
{
unsigned int nBands = node->m_Means.size(); //this->m_InputImage->GetNumberOfComponentsPerPixel();
......@@ -55,7 +55,7 @@ namespace lsgrm
memory += 4 * nBands * sizeof(float); // size of the 4 attributes, multiplied by the nb. of bands
memory += node->m_Edges.size() * sizeof(EdgeType); // size of the edges
return memory;
}
}
} // end of namespace lsrm
#endif
......
......@@ -108,10 +108,6 @@ void Controller<TSegmenter>::RunSegmentation()
{
numberOfIterationsRemaining -= numberOfIterationsForPartialSegmentations;
}
else
{
isFusion = false;
}
#ifdef OTB_USE_MPI
// Gathering useful variables
......@@ -152,11 +148,21 @@ void Controller<TSegmenter>::RunSegmentation()
itkExceptionMacro(<< "No more possible fusions, but can not store the output graph");
}
}
else // tiling_mode is none
else if (m_TilingMode == LSGRM_TILING_NONE)// tiling_mode is none
{
// todo use classic grm
// Use classic grm
TSegmenter segmenter;
segmenter.SetParam(m_SpecificParameters);
segmenter.SetThreshold(m_Threshold);
segmenter.SetDoFastSegmentation(true);
segmenter.SetNumberOfIterations(m_NumberOfIterations);
segmenter.SetInput(m_InputImage);
segmenter.Update();
}
else
{
itkExceptionMacro(<<"Unknow tiling mode!");
}
}
......
......@@ -6,10 +6,10 @@
namespace lsgrm
{
template<class TImage>
void
FullLambdaScheduleSegmenter<TImage>::WriteSpecificAttributes(NodePointerType node, FILE * nodeStream)
{
template<class TImage>
void
FullLambdaScheduleSegmenter<TImage>::WriteSpecificAttributes(NodePointerType node, FILE * nodeStream)
{
std::size_t bands = node->m_Means.size();
fwrite(&(bands), sizeof(bands), 1, nodeStream);
......@@ -17,12 +17,12 @@ namespace lsgrm
{
fwrite(&(node->m_Means[b]), sizeof(node->m_Means[b]), 1, nodeStream);
}
}
}
template<class TImage>
void
FullLambdaScheduleSegmenter<TImage>::ReadSpecificAttributes(NodePointerType node, FILE * nodeStream)
{
template<class TImage>
void
FullLambdaScheduleSegmenter<TImage>::ReadSpecificAttributes(NodePointerType node, FILE * nodeStream)
{
std::size_t bands;
fread(&(bands), sizeof(bands), 1, nodeStream);
node->m_Means.assign(bands, 0);
......@@ -31,12 +31,12 @@ namespace lsgrm
{
fread(&(node->m_Means[b]), sizeof(node->m_Means[b]), 1, nodeStream);
}
}
}
template<class TImage>
long long unsigned int
FullLambdaScheduleSegmenter<TImage>::GetNodeMemory(NodePointerType &node)
{
template<class TImage>
long long unsigned int
FullLambdaScheduleSegmenter<TImage>::GetNodeMemory(NodePointerType &node)
{
unsigned int nBands = node->m_Means.size(); //this->m_InputImage->GetNumberOfComponentsPerPixel();
......@@ -46,7 +46,7 @@ namespace lsgrm
memory += 1 * nBands * sizeof(float); // size of the 1 attribute, multiplied by the nb. of bands
memory += node->m_Edges.size() * sizeof(EdgeType); // size of the edges
return memory;
}
}
} // end of namespace lsrm
#endif
......
......@@ -14,10 +14,10 @@
namespace lsgrm
{
template<class TGraph>
class GraphToOtbImage
{
public:
template<class TGraph>
class GraphToOtbImage
{
public:
/* Some convenient typedefs */
typedef TGraph GraphType;
......@@ -32,7 +32,7 @@ namespace lsgrm
LabelImageType::Pointer GetLabelImage(const GraphType& graph,
const unsigned int width,
const unsigned int height);
};
};
} // end of namespace lsrm
#include "lsgrmGraphToOtbImage.txx"
......
......@@ -6,9 +6,9 @@
namespace lsgrm
{
template<class TGraph>
typename GraphToOtbImage<TGraph>::LabelImageType::Pointer
GraphToOtbImage<TGraph>::GetLabelImage(const GraphType& graph,
template<class TGraph>
typename GraphToOtbImage<TGraph>::LabelImageType::Pointer
GraphToOtbImage<TGraph>::GetLabelImage(const GraphType& graph,
const unsigned int width,
const unsigned int height)
{
......
......@@ -4,10 +4,10 @@ namespace lsgrm
{
enum RelativePosition{
POS_TOP,
POS_RIGHT,
POS_BOTTOM,
POS_LEFT
POS_TOP,
POS_RIGHT,
POS_BOTTOM,
POS_LEFT
};
enum NeighborhoodRelativePosition{
......@@ -29,7 +29,7 @@ std::vector<ProcessingTile> SplitOTBImage(TInputImage * imagePtr, // input image
unsigned int &nbTilesX,
unsigned int &nbTilesY,
std::string temporaryFilesPrefix)
{
{
std::vector<ProcessingTile> tiles;
......@@ -173,5 +173,5 @@ std::vector<ProcessingTile> SplitOTBImage(TInputImage * imagePtr, // input image
} // for(unsigned int row = 0; row < nbTilesY; ++row)
return tiles;
}
}
} // end of namespace lsgrm
......@@ -6,10 +6,10 @@
namespace lsgrm
{
template<class TImage>
void
SpringSegmenter<TImage>::WriteSpecificAttributes(NodePointerType node, FILE * nodeStream)
{
template<class TImage>
void
SpringSegmenter<TImage>::WriteSpecificAttributes(NodePointerType node, FILE * nodeStream)
{
std::size_t bands = node->m_Means.size();
fwrite(&(bands), sizeof(bands), 1, nodeStream);
......@@ -17,12 +17,12 @@ namespace lsgrm
{
fwrite(&(node->m_Means[b]), sizeof(node->m_Means[b]), 1, nodeStream);
}
}
}
template<class TImage>
void
SpringSegmenter<TImage>::ReadSpecificAttributes(NodePointerType node, FILE * nodeStream)
{
template<class TImage>
void
SpringSegmenter<TImage>::ReadSpecificAttributes(NodePointerType node, FILE * nodeStream)
{
std::size_t bands;
fread(&(bands), sizeof(bands), 1, nodeStream);
node->m_Means.assign(bands, 0);
......@@ -31,12 +31,12 @@ namespace lsgrm
{
fread(&(node->m_Means[b]), sizeof(node->m_Means[b]), 1, nodeStream);
}
}
}
template<class TImage>
long long unsigned int
SpringSegmenter<TImage>::GetNodeMemory(NodePointerType &node)
{
template<class TImage>
long long unsigned int
SpringSegmenter<TImage>::GetNodeMemory(NodePointerType &node)
{
unsigned int nBands = node->m_Means.size(); //this->m_InputImage->GetNumberOfComponentsPerPixel();
......@@ -46,7 +46,7 @@ namespace lsgrm
memory += 1 * nBands * sizeof(float); // size of the 1 attribute, multiplied by the nb. of bands
memory += node->m_Edges.size() * sizeof(EdgeType); // size of the edges
return memory;
}
}
} // end of namespace lsrm
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment