Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
otb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Youssefi
otb
Commits
37f4be43
Commit
37f4be43
authored
16 years ago
by
OTB Bot
Browse files
Options
Downloads
Patches
Plain Diff
modif double declaration ( warning VS7.1)
parent
27850c83
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Code/Markov/otbMRFSamplerRandomMAP.h
+169
-168
169 additions, 168 deletions
Code/Markov/otbMRFSamplerRandomMAP.h
with
169 additions
and
168 deletions
Code/Markov/otbMRFSamplerRandomMAP.h
+
169
−
168
View file @
37f4be43
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef _MRFSamplerRandomMAP_h
#define _MRFSamplerRandomMAP_h
#include
"itkMersenneTwisterRandomVariateGenerator.h"
#include
"otbMRFSampler.h"
namespace
otb
{
/**
* \class MRFSamplerRandomMAP
* \brief This is the base class for sampler methods used in the MRF framework.
*
* This is one sampler to be used int he MRF framework. This sampler select the
* value randomly according to the apriori probability.
*
* The probability is defined from the energy as:
*
* \f[ P(X=x)= \frac{1}{Z} \exp^{-U(x)} \f]
*
* where \f$ Z = \sum_x \exp^{-U(x)}\f$
*
*/
template
<
class
TInput1
,
class
TInput2
>
class
ITK_EXPORT
MRFSamplerRandomMAP
:
public
MRFSampler
<
TInput1
,
TInput2
>
{
public:
typedef
MRFSamplerRandomMAP
Self
;
typedef
otb
::
MRFSampler
<
TInput1
,
TInput2
>
Superclass
;
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
typedef
itk
::
SmartPointer
<
const
Self
>
ConstPointer
;
typedef
typename
Superclass
::
InputImageNeighborhoodIterator
InputImageNeighborhoodIterator
;
typedef
typename
Superclass
::
LabelledImageNeighborhoodIterator
LabelledImageNeighborhoodIterator
;
typedef
typename
Superclass
::
LabelledImagePixelType
LabelledImagePixelType
;
typedef
typename
Superclass
::
InputImagePixelType
InputImagePixelType
;
typedef
typename
Superclass
::
EnergyFidelityType
EnergyFidelityType
;
typedef
typename
Superclass
::
EnergyRegularizationType
EnergyRegularizationType
;
typedef
typename
Superclass
::
EnergyFidelityPointer
EnergyFidelityPointer
;
typedef
typename
Superclass
::
EnergyRegularizationPointer
EnergyRegularizationPointer
;
typedef
itk
::
Statistics
::
MersenneTwisterRandomVariateGenerator
RandomGeneratorType
;
itkNewMacro
(
Self
);
itkTypeMacro
(
MRFSamplerRandomMAP
,
MRFSampler
);
void
SetNumberOfClasses
(
const
unsigned
int
nClasses
)
{
if
(
nClasses
!=
this
->
m_NumberOfClasses
||
energiesInvalid
==
true
)
{
this
->
m_NumberOfClasses
=
nClasses
;
if
(
energy
!=
NULL
)
free
(
energy
);
if
(
repartitionFunction
!=
NULL
)
free
(
repartitionFunction
);
energy
=
(
double
*
)
calloc
(
this
->
m_NumberOfClasses
,
sizeof
(
double
));
repartitionFunction
=
(
double
*
)
calloc
(
this
->
m_NumberOfClasses
,
sizeof
(
double
));
this
->
Modified
();
}
}
inline
int
Compute
(
const
InputImageNeighborhoodIterator
&
itData
,
const
LabelledImageNeighborhoodIterator
&
itRegul
)
{
if
(
this
->
m_NumberOfClasses
==
0
)
{
itkExceptionMacro
(
<<
"NumberOfClasse has to be greater than 0."
);
}
this
->
m_EnergyBefore
=
this
->
m_EnergyFidelity
->
GetValue
(
itData
,
itRegul
.
GetCenterPixel
());
this
->
m_EnergyBefore
+=
this
->
m_Lambda
*
this
->
m_EnergyRegularization
->
GetValue
(
itRegul
,
itRegul
.
GetCenterPixel
());
//Try all possible value (how to be generic ?)
this
->
m_EnergyAfter
=
this
->
m_EnergyBefore
;
//default values to current one
this
->
m_Value
=
itRegul
.
GetCenterPixel
();
//Compute probability for each possibility
double
totalProba
=
0.0
;
for
(
unsigned
int
valueCurrent
=
0
;
valueCurrent
<
this
->
m_NumberOfClasses
;
++
valueCurrent
)
{
this
->
m_EnergyCurrent
=
this
->
m_EnergyFidelity
->
GetValue
(
itData
,
static_cast
<
LabelledImagePixelType
>
(
valueCurrent
));
this
->
m_EnergyCurrent
+=
this
->
m_Lambda
*
this
->
m_EnergyRegularization
->
GetValue
(
itRegul
,
static_cast
<
LabelledImagePixelType
>
(
valueCurrent
));
energy
[
valueCurrent
]
=
this
->
m_EnergyCurrent
;
repartitionFunction
[
valueCurrent
]
=
vcl_exp
(
-
this
->
m_EnergyCurrent
)
+
totalProba
;
totalProba
=
repartitionFunction
[
valueCurrent
];
}
//Pick a value according to probability
//double select = (m_Generator->GetIntegerVariate()/(double(RAND_MAX)+1) * totalProba);
double
select
=
(
m_Generator
->
GetIntegerVariate
()
/
(
double
(
itk
::
NumericTraits
<
RandomGeneratorType
::
IntegerType
>::
max
())
+
1
)
*
totalProba
);
unsigned
int
valueCurrent
=
0
;
while
(
valueCurrent
<
this
->
GetNumberOfClasses
()
&&
repartitionFunction
[
valueCurrent
]
<=
select
)
{
valueCurrent
++
;
}
if
(
valueCurrent
==
this
->
GetNumberOfClasses
()
)
{
valueCurrent
=
this
->
GetNumberOfClasses
()
-
1
;
}
if
(
this
->
m_Value
!=
static_cast
<
LabelledImagePixelType
>
(
valueCurrent
))
{
this
->
m_Value
=
static_cast
<
LabelledImagePixelType
>
(
valueCurrent
);
this
->
m_EnergyAfter
=
energy
[
static_cast
<
unsigned
int
>
(
valueCurrent
)];
}
this
->
m_DeltaEnergy
=
this
->
m_EnergyAfter
-
this
->
m_EnergyBefore
;
return
0
;
}
/** Methods to cancel random effects.*/
void
InitializeSeed
(
int
seed
){
m_Generator
->
SetSeed
(
seed
);
}
void
InitializeSeed
(){
m_Generator
->
SetSeed
();
}
private
:
double
*
repartitionFunction
;
double
*
energy
;
bool
energiesInvalid
;
RandomGeneratorType
::
Pointer
m_Generator
;
protected
:
// The constructor and destructor.
MRFSamplerRandomMAP
()
{
energy
=
NULL
;
repartitionFunction
=
NULL
;
energiesInvalid
=
true
;
m_Generator
=
RandomGeneratorType
::
New
();
m_Generator
->
SetSeed
();
}
virtual
~
MRFSamplerRandomMAP
()
{
if
(
energy
!=
NULL
)
free
(
energy
);
if
(
repartitionFunction
!=
NULL
)
free
(
repartitionFunction
);
}
};
}
#endif
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef _MRFSamplerRandomMAP_h
#define _MRFSamplerRandomMAP_h
#include
"itkMersenneTwisterRandomVariateGenerator.h"
#include
"otbMRFSampler.h"
namespace
otb
{
/**
* \class MRFSamplerRandomMAP
* \brief This is the base class for sampler methods used in the MRF framework.
*
* This is one sampler to be used int he MRF framework. This sampler select the
* value randomly according to the apriori probability.
*
* The probability is defined from the energy as:
*
* \f[ P(X=x)= \frac{1}{Z} \exp^{-U(x)} \f]
*
* where \f$ Z = \sum_x \exp^{-U(x)}\f$
*
*/
template
<
class
TInput1
,
class
TInput2
>
class
ITK_EXPORT
MRFSamplerRandomMAP
:
public
MRFSampler
<
TInput1
,
TInput2
>
{
public:
typedef
MRFSamplerRandomMAP
Self
;
typedef
otb
::
MRFSampler
<
TInput1
,
TInput2
>
Superclass
;
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
typedef
itk
::
SmartPointer
<
const
Self
>
ConstPointer
;
typedef
typename
Superclass
::
InputImageNeighborhoodIterator
InputImageNeighborhoodIterator
;
typedef
typename
Superclass
::
LabelledImageNeighborhoodIterator
LabelledImageNeighborhoodIterator
;
typedef
typename
Superclass
::
LabelledImagePixelType
LabelledImagePixelType
;
typedef
typename
Superclass
::
InputImagePixelType
InputImagePixelType
;
typedef
typename
Superclass
::
EnergyFidelityType
EnergyFidelityType
;
typedef
typename
Superclass
::
EnergyRegularizationType
EnergyRegularizationType
;
typedef
typename
Superclass
::
EnergyFidelityPointer
EnergyFidelityPointer
;
typedef
typename
Superclass
::
EnergyRegularizationPointer
EnergyRegularizationPointer
;
typedef
itk
::
Statistics
::
MersenneTwisterRandomVariateGenerator
RandomGeneratorType
;
itkNewMacro
(
Self
);
itkTypeMacro
(
MRFSamplerRandomMAP
,
MRFSampler
);
void
SetNumberOfClasses
(
const
unsigned
int
nClasses
)
{
if
(
nClasses
!=
this
->
m_NumberOfClasses
||
energiesInvalid
==
true
)
{
this
->
m_NumberOfClasses
=
nClasses
;
if
(
energy
!=
NULL
)
free
(
energy
);
if
(
repartitionFunction
!=
NULL
)
free
(
repartitionFunction
);
energy
=
(
double
*
)
calloc
(
this
->
m_NumberOfClasses
,
sizeof
(
double
));
repartitionFunction
=
(
double
*
)
calloc
(
this
->
m_NumberOfClasses
,
sizeof
(
double
));
this
->
Modified
();
}
}
inline
int
Compute
(
const
InputImageNeighborhoodIterator
&
itData
,
const
LabelledImageNeighborhoodIterator
&
itRegul
)
{
if
(
this
->
m_NumberOfClasses
==
0
)
{
itkExceptionMacro
(
<<
"NumberOfClasse has to be greater than 0."
);
}
this
->
m_EnergyBefore
=
this
->
m_EnergyFidelity
->
GetValue
(
itData
,
itRegul
.
GetCenterPixel
());
this
->
m_EnergyBefore
+=
this
->
m_Lambda
*
this
->
m_EnergyRegularization
->
GetValue
(
itRegul
,
itRegul
.
GetCenterPixel
());
//Try all possible value (how to be generic ?)
this
->
m_EnergyAfter
=
this
->
m_EnergyBefore
;
//default values to current one
this
->
m_Value
=
itRegul
.
GetCenterPixel
();
//Compute probability for each possibility
double
totalProba
=
0.0
;
unsigned
int
valueCurrent
=
0
;
for
(
valueCurrent
=
0
;
valueCurrent
<
this
->
m_NumberOfClasses
;
++
valueCurrent
)
{
this
->
m_EnergyCurrent
=
this
->
m_EnergyFidelity
->
GetValue
(
itData
,
static_cast
<
LabelledImagePixelType
>
(
valueCurrent
));
this
->
m_EnergyCurrent
+=
this
->
m_Lambda
*
this
->
m_EnergyRegularization
->
GetValue
(
itRegul
,
static_cast
<
LabelledImagePixelType
>
(
valueCurrent
));
energy
[
valueCurrent
]
=
this
->
m_EnergyCurrent
;
repartitionFunction
[
valueCurrent
]
=
vcl_exp
(
-
this
->
m_EnergyCurrent
)
+
totalProba
;
totalProba
=
repartitionFunction
[
valueCurrent
];
}
//Pick a value according to probability
//double select = (m_Generator->GetIntegerVariate()/(double(RAND_MAX)+1) * totalProba);
double
select
=
(
m_Generator
->
GetIntegerVariate
()
/
(
double
(
itk
::
NumericTraits
<
RandomGeneratorType
::
IntegerType
>::
max
())
+
1
)
*
totalProba
);
valueCurrent
=
0
;
while
(
valueCurrent
<
this
->
GetNumberOfClasses
()
&&
repartitionFunction
[
valueCurrent
]
<=
select
)
{
valueCurrent
++
;
}
if
(
valueCurrent
==
this
->
GetNumberOfClasses
()
)
{
valueCurrent
=
this
->
GetNumberOfClasses
()
-
1
;
}
if
(
this
->
m_Value
!=
static_cast
<
LabelledImagePixelType
>
(
valueCurrent
))
{
this
->
m_Value
=
static_cast
<
LabelledImagePixelType
>
(
valueCurrent
);
this
->
m_EnergyAfter
=
energy
[
static_cast
<
unsigned
int
>
(
valueCurrent
)];
}
this
->
m_DeltaEnergy
=
this
->
m_EnergyAfter
-
this
->
m_EnergyBefore
;
return
0
;
}
/** Methods to cancel random effects.*/
void
InitializeSeed
(
int
seed
){
m_Generator
->
SetSeed
(
seed
);
}
void
InitializeSeed
(){
m_Generator
->
SetSeed
();
}
private
:
double
*
repartitionFunction
;
double
*
energy
;
bool
energiesInvalid
;
RandomGeneratorType
::
Pointer
m_Generator
;
protected
:
// The constructor and destructor.
MRFSamplerRandomMAP
()
{
energy
=
NULL
;
repartitionFunction
=
NULL
;
energiesInvalid
=
true
;
m_Generator
=
RandomGeneratorType
::
New
();
m_Generator
->
SetSeed
();
}
virtual
~
MRFSamplerRandomMAP
()
{
if
(
energy
!=
NULL
)
free
(
energy
);
if
(
repartitionFunction
!=
NULL
)
free
(
repartitionFunction
);
}
};
}
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment