Skip to content
Snippets Groups Projects
Commit cd8fee8f authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

Correction de la classe bayesian fusion pour éviter de recalculer les stats à chaque stream.

parent a70ae0b9
No related branches found
No related tags found
No related merge requests found
......@@ -290,7 +290,6 @@ namespace otb {
// sum of squares
for( i = 0; i < numberOfThreads; i++)
{
std::cout<<i<<std::endl;
count += m_Count[i];
/** TODO
* To modify using + method operator. If we use it now -> exceptionmacro (no GetClassName...)
......@@ -351,7 +350,7 @@ namespace otb {
tempTranspose = pixelSumMatrix.GetTranspose();
covMatrixTemp = pixelSumMatrix*tempTranspose;
/** TODO
* A modifier en utilisant l'oprateur + de la mthode. Pour le moment probleme avec exceptionmacro (pas de GetClassName...)
* To modify using - method operator. If we use it now -> exceptionmacro (no GetClassName...)
*covMatrix -= covMatrixTemp;
**/
if( (covMatrix.Rows() != covMatrixTemp.Rows()) || (covMatrix.Cols() != covMatrixTemp.Cols()))
......@@ -430,9 +429,8 @@ namespace otb {
++it;
progress.CompletedPixel();
pixelTransposeVector = pixelVector.GetTranspose();
/** TODO
* A modifier en utilisant l'oprateur + de la mthode. Pour le moment probleme avec exceptionmacro (pas de GetClassName...)
/** TODO
* To modify using + method operator. If we use it now -> exceptionmacro (no GetClassName...)
* m_XX[threadId]+=pixelVector*pixelTransposeVector;
**/
tempMatrix = pixelVector*pixelTransposeVector;
......
......@@ -245,15 +245,18 @@ public:
itkSetMacro(S, float);
/** Give the S coefficient. */
itkGetConstReferenceMacro(S, float);
protected:
BayesianFusionFilter();
virtual ~BayesianFusionFilter();
/** Initialize some accumulators before the threads run. */
/** Check if internal statistics need to be computed, and do so */
void BeforeThreadedGenerateData ();
/** Compute internal statistics required for fusion */
void ComputeInternalStatistics(void);
/** Call the superclass implementation and set the StatisticsHaveBeenGenerated
* flag to false */
virtual void Modified(void);
private:
/** Ponderation declaration*/
float m_Lambda;
......@@ -266,7 +269,8 @@ private:
MatrixType m_Beta;
/** Optimisation matrix */
MatrixType m_Vcondopt;
/** True if internal statistics have been generated */
bool m_StatisticsHaveBeenGenerated;
};
} // end namespace otb
......
......@@ -40,6 +40,7 @@ namespace otb
{
m_Lambda = 0.9999;
m_S = 1;
m_StatisticsHaveBeenGenerated = false;
}
......@@ -55,7 +56,20 @@ namespace otb
{
}
template <class TInputMultiSpectralImage,
class TInputMultiSpectralInterpImage,
class TInputPanchroImage,
class TOutputImage>
void
BayesianFusionFilter<TInputMultiSpectralImage,
TInputMultiSpectralInterpImage,
TInputPanchroImage,
TOutputImage>
::Modified()
{
Superclass::Modified();
m_StatisticsHaveBeenGenerated = false;
}
template <class TInputMultiSpectralImage,
class TInputMultiSpectralInterpImage,
......@@ -68,7 +82,25 @@ namespace otb
TOutputImage>
::BeforeThreadedGenerateData ()
{
OutputImageRegionType msiRequestedRegion = this->GetMultiSpectInterp()->GetRequestedRegion();
if(!m_StatisticsHaveBeenGenerated)
{
this->ComputeInternalStatistics();
m_StatisticsHaveBeenGenerated = true;
}
}
template <class TInputMultiSpectralImage,
class TInputMultiSpectralInterpImage,
class TInputPanchroImage,
class TOutputImage>
void
BayesianFusionFilter<TInputMultiSpectralImage,
TInputMultiSpectralInterpImage,
TInputPanchroImage,
TOutputImage>
::ComputeInternalStatistics()
{
OutputImageRegionType msiRequestedRegion = this->GetMultiSpectInterp()->GetRequestedRegion();
OutputImageRegionType msRequestedRegion = this->GetMultiSpect()->GetRequestedRegion();
OutputImageRegionType panchroRequestedRegion = this->GetPanchro()->GetRequestedRegion();
......@@ -95,8 +127,10 @@ namespace otb
covComputefilter->SetInput(multiSpecInterp);
covComputefilter->Update();
MatrixType m_CovarianceMatrix = covComputefilter->GetCovariance();
otbMsgDebugMacro(<<"Covariance: "<<m_CovarianceMatrix);
m_CovarianceInvMatrix = m_CovarianceMatrix.GetInverse();
/** Beta computation : Regression model coefficient */
......@@ -120,8 +154,10 @@ namespace otb
msTransposePan->SetSecondInput( caster->GetOutput() );
msTransposeMs->Update();
otbMsgDebugMacro(<<"MsTMs: "<<msTransposeMs->GetResultOutput()->Get());
msTransposePan->Update();
otbMsgDebugMacro(<<"MsTPan: "<<msTransposePan->GetResultOutput()->Get());
MatrixType temp;
temp = msTransposeMs->GetResultOutput()->Get().GetInverse();
m_Beta = temp*msTransposePan->GetResultOutput()->Get();
......@@ -132,6 +168,7 @@ namespace otb
panTransposePan->SetFirstInput(caster->GetOutput());
panTransposePan->SetSecondInput(caster->GetOutput());
panTransposePan->Update();
otbMsgDebugMacro(<<"PanTPan: "<<msTransposePan->GetResultOutput()->Get());
MatrixType S, tempS, tempS2;
S = panTransposePan->GetResultOutput()->Get();
tempS = msTransposePan->GetResultOutput()->Get().GetTranspose();
......@@ -282,6 +319,8 @@ namespace otb
panchro->SetRequestedRegion(panchroRequestedRegion);
panchro->PropagateRequestedRegion();
panchro->UpdateOutputData();
std::cout<<"End of BeforeThreaderGenerateData."<<std::endl;
}
} // end namespace otb
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment