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