Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Cresson Remi
LSGRM
Commits
2ed36bce
Commit
2ed36bce
authored
Aug 24, 2016
by
remicres
Browse files
ADD: criterion can be chosen amongst bs/ed/fls
parent
d70b03f3
Changes
1
Show whitespace changes
Inline
Side-by-side
app/otbLSGRM.cxx
View file @
2ed36bce
...
...
@@ -12,7 +12,9 @@
// GRM
#include <iostream>
#include "lsrmBaatzSegmenter.h"
#include "lsgrmBaatzSegmenter.h"
#include "lsgrmSpringSegmenter.h"
#include "lsgrmFullLambdaScheduleSegmenter.h"
#include "lsgrmController.h"
// system tools
...
...
@@ -37,6 +39,15 @@ public:
itkNewMacro
(
Self
);
itkTypeMacro
(
LSGRM
,
Application
);
/** Useful typedefs */
typedef
otb
::
VectorImage
<
float
,
2
>
ImageType
;
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:
/* Tiling mode choice */
...
...
@@ -47,6 +58,14 @@ private:
TILING_NONE
};
/* Criterion choice */
enum
Criterion
{
CRITERION_BAATZ
,
CRITERION_SPRING
,
CRITERION_FLS
};
void
DoInit
()
{
SetName
(
"GenericRegionMerging"
);
...
...
@@ -54,35 +73,33 @@ private:
"(GRM) and provides currently 3 homogeneity criteria: Euclidean Distance, "
"Full Lambda Schedule and Baatz & Schape criterion."
);
// Input and Output images
AddParameter
(
ParameterType_InputImage
,
"in"
,
"Input Image"
);
AddParameter
(
ParameterType_OutputImage
,
"out"
,
"Ouput Label Image"
);
SetDefaultOutputPixelType
(
"out"
,
ImagePixelType_uint32
);
// AddParameter(ParameterType_Choice, "criterion", "Homogeneity criterion to use");
// AddChoice("criterion.bs", "Baatz & Schape");
// AddChoice("criterion.ed", "Euclidean Distance");
// AddChoice("criterion.fls", "Full Lambda Schedule");
// Criterion choice
AddParameter
(
ParameterType_Choice
,
"criterion"
,
"Homogeneity criterion to use"
);
AddChoice
(
"criterion.bs"
,
"Baatz & Schape"
);
AddChoice
(
"criterion.ed"
,
"Euclidean Distance"
);
AddChoice
(
"criterion.fls"
,
"Full Lambda Schedule"
);
// Generic parameters
AddParameter
(
ParameterType_Float
,
"threshold"
,
"Threshold for the criterion"
);
AddParameter
(
ParameterType_Int
,
"niter"
,
"Maximum number of iterations"
);
SetDefaultParameterInt
(
"niter"
,
75
);
MandatoryOff
(
"niter"
);
AddParameter
(
ParameterType_Int
,
"speed"
,
"Activate it to boost the segmentation speed"
);
SetDefaultParameterInt
(
"speed"
,
0
);
MandatoryOff
(
"speed"
);
// For Baatz & Schape
AddParameter
(
ParameterType_Float
,
"cw"
,
"Weight for the spectral homogeneity"
);
SetDefaultParameterFloat
(
"cw"
,
0.5
);
MandatoryOff
(
"cw"
);
AddParameter
(
ParameterType_Float
,
"sw"
,
"Weight for the spatial homogeneity"
);
SetDefaultParameterFloat
(
"sw"
,
0.5
);
MandatoryOff
(
"sw"
);
// Specific parameters for Baatz & Schape
AddParameter
(
ParameterType_Float
,
"criterion.bs.cw"
,
"Weight for the spectral homogeneity"
);
SetDefaultParameterFloat
(
"criterion.bs.cw"
,
0.5
);
MandatoryOff
(
"criterion.bs.cw"
);
AddParameter
(
ParameterType_Float
,
"criterion.bs.sw"
,
"Weight for the spatial homogeneity"
);
SetDefaultParameterFloat
(
"criterion.bs.sw"
,
0.5
);
MandatoryOff
(
"criterion.bs.sw"
);
// For large scale
AddParameter
(
ParameterType_Directory
,
"tmpdir"
,
"
temporary d
irectory for t
iles and graph
s"
);
AddParameter
(
ParameterType_Directory
,
"tmpdir"
,
"
D
irectory for t
emporary file
s"
);
AddParameter
(
ParameterType_Choice
,
"tiling"
,
"Tiling layout for the large scale segmentation"
);
AddChoice
(
"tiling.auto"
,
"Automatic tiling layout"
);
AddChoice
(
"tiling.user"
,
"User tiling layout"
);
...
...
@@ -97,6 +114,7 @@ private:
{
}
/*
* Return a prefix for temporary files
*/
...
...
@@ -122,66 +140,112 @@ private:
return
prefix
;
}
void
DoExecute
()
{
/*
To add:
internal memory available
If we have to do the image division
if we have to clean up the directory
the output directory in case the global graph cannot fit in memory
* This function sets the generic parameters of a controller and runs the segmentation
*/
template
<
class
TController
>
UInt32ImageType
::
Pointer
SetGenericParametersAndRunSegmentation
(
typename
TController
::
Pointer
&
controller
)
{
// Set input image
controller
->
SetInputImage
(
GetParameterFloatVectorImage
(
"in"
));
using
ImageType
=
otb
::
VectorImage
<
float
,
2
>
;
using
SegmenterType
=
lsgrm
::
BaatzSeg
me
n
ter
<
ImageType
>
;
using
C
ontroller
Type
=
lsgrm
::
Controller
<
SegmenterType
>
;
// Set threshold
float
thres
=
GetPara
meter
Float
(
"threshold"
)
;
c
ontroller
->
SetThreshold
(
thres
*
thres
)
;
ImageType
::
Pointer
inputImage
=
GetParameterFloatVectorImage
(
"in"
);
// Set number of iterations
controller
->
SetNumberOfIterations
(
GetParameterInt
(
"niter"
));
ControllerType
controller
;
controller
.
SetInputImage
(
inputImage
);
controller
.
SetTemporaryFilesPrefix
(
this
->
GetTemporaryFilesPrefix
());
// Set temporary files prefix
controller
->
SetTemporaryFilesPrefix
(
this
->
GetTemporaryFilesPrefix
());
//
T
iling mode
//
Switch t
iling mode
int
inputTilingMode
=
GetParameterInt
(
"tiling"
);
if
(
inputTilingMode
==
TILING_AUTO
)
{
controller
.
SetTilingModeAuto
();
// Automatic mode
controller
->
SetTilingModeAuto
();
}
else
if
(
inputTilingMode
==
TILING_USER
)
{
// User
controller
.
SetTilingModeUser
();
controller
.
SetTileWidth
(
GetParameterInt
(
"tiling.user.sizex"
));
controller
.
SetTileHeight
(
GetParameterInt
(
"tiling.user.sizey"
));
controller
.
SetNumberOfFirstIterations
(
GetParameterInt
(
"tiling.user.nfirstiter"
));
controller
.
SetInternalMemoryAvailable
(
GetParameterInt
(
"tiling.user.memory"
));
// User
mode
controller
->
SetTilingModeUser
();
controller
->
SetTileWidth
(
GetParameterInt
(
"tiling.user.sizex"
));
controller
->
SetTileHeight
(
GetParameterInt
(
"tiling.user.sizey"
));
controller
->
SetNumberOfFirstIterations
(
GetParameterInt
(
"tiling.user.nfirstiter"
));
controller
->
SetInternalMemoryAvailable
(
GetParameterInt
(
"tiling.user.memory"
));
}
else
if
(
inputTilingMode
==
TILING_NONE
)
{
controller
.
SetTilingModeNone
();
// None mode
controller
->
SetTilingModeNone
();
}
else
{
otbAppLogFATAL
(
"Unknow input tiling mode!"
);
otbAppLogFATAL
(
"Unknow tiling mode!"
);
}
// Run the segmentation
controller
->
RunSegmentation
();
// Get temporary files list
m_TemporaryFilesList
=
controller
->
GetTemporaryFilesList
();
// Return the label image
return
controller
->
GetLabeledClusteredOutput
();
}
void
DoExecute
()
{
/*
To add:
the output directory in case the global graph cannot fit in memory
*/
// Input image
ImageType
::
Pointer
inputImage
=
GetParameterFloatVectorImage
(
"in"
);
// Output image
UInt32ImageType
::
Pointer
labelImage
=
UInt32ImageType
::
New
();
// Switch criterion
int
inputCriterion
=
GetParameterInt
(
"criterion"
);
if
(
inputCriterion
==
CRITERION_BAATZ
)
{
// Baatz controller
BaatzControllerType
::
Pointer
baatzController
=
BaatzControllerType
::
New
();
// Specific parameters
grm
::
BaatzParam
params
;
params
.
m_SpectralWeight
=
GetParameterFloat
(
"cw"
);
params
.
m_ShapeWeight
=
GetParameterFloat
(
"sw"
);
controller
.
SetSpecificParameters
(
params
);
float
thres
=
GetParameterFloat
(
"threshold"
);
controller
.
SetThreshold
(
thres
*
thres
);
controller
.
SetNumberOfIterations
(
GetParameterInt
(
"niter"
));
params
.
m_SpectralWeight
=
GetParameterFloat
(
"criterion.bs.cw"
);
params
.
m_ShapeWeight
=
GetParameterFloat
(
"criterion.bs.sw"
);
baatzController
->
SetSpecificParameters
(
params
);
// Run the segmentation
controller
.
SetDebug
(
true
);
controller
.
RunSegmentation
();
// Run segmentation
labelImage
=
SetGenericParametersAndRunSegmentation
<
BaatzControllerType
>
(
baatzController
);
}
else
if
(
inputCriterion
==
CRITERION_SPRING
)
{
// Spring controller
SpringControllerType
::
Pointer
springController
=
SpringControllerType
::
New
();
// Output images
UInt32ImageType
::
Pointer
labelImage
=
controller
.
GetLabeledClusteredOutput
();;
// Run segmentation
labelImage
=
SetGenericParametersAndRunSegmentation
<
SpringControllerType
>
(
springController
);
}
else
if
(
inputCriterion
==
CRITERION_FLS
)
{
// Full Lambda Schedule (FLS) controller
FLSControllerType
::
Pointer
flsController
=
FLSControllerType
::
New
();
// Run segmentation
labelImage
=
SetGenericParametersAndRunSegmentation
<
FLSControllerType
>
(
flsController
);
}
else
{
otbAppLogFATAL
(
"Unknow criterion!"
)
}
// Set output image projection, origin and spacing for labelImage
labelImage
->
SetProjectionRef
(
inputImage
->
GetProjectionRef
());
...
...
@@ -189,8 +253,6 @@ private:
labelImage
->
SetSpacing
(
inputImage
->
GetSpacing
());
SetParameterOutputImage
<
UInt32ImageType
>
(
"out"
,
labelImage
);
// Get temporary files list
m_TemporaryFilesList
=
controller
.
GetTemporaryFilesList
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment