Example #1
0
void PyramidDenoiser::DenoiseLevelBivariate(int level)
{
   if (level < (int)(mpPyramid->GetNumberOfScales() - 1))
   {
      PyramidLevel<double>* pBandSetCurrent;
      PyramidLevel<double>* pBandSetParent;
      if (level != -1)
      {
         pBandSetCurrent = mpPyramid->GetRecursiveScale(level);
         pBandSetParent = mpPyramid->GetRecursiveScale(level+1);
      }
      else
      {
         pBandSetCurrent = mpPyramid->GetResidualScale();
         pBandSetParent = mpPyramid->GetRecursiveScale(0);
      }

      double avgVariance = 0.0;

      double scaleNoiseVariance = mSigmaNoise / GetScaledNoiseVarianceFactor( level );
      double scaleParentChildFactor = GetScaledParentChildFactor( level);

      for (int orientationIndex = 0; orientationIndex < pBandSetCurrent->GetNumberOfOrientations(); orientationIndex++)
      {
         ArrayGrid<double>* pBandCurrent = pBandSetCurrent->GetOrientedBand( orientationIndex);
         ArrayGrid<double>* pBandParent = pBandSetParent->GetOrientedBand( orientationIndex);

         double meanVal     = GridStatistics<double>::GetGridMean( pBandCurrent );
         double varianceVal = GridStatistics<double>::GetGridVariance( pBandCurrent, meanVal );

         #ifdef DEBUG
         cout << "Denoising level " << level << " and orientationIndex " << orientationIndex
              << ", variance is " << varianceVal << " and scaled noise variance = " << scaleNoiseVariance << endl << flush;
         #endif
         avgVariance += varianceVal;


         for (int y = 0; y < pBandCurrent->GetHeight(); y++)
         {
            for (int x = 0; x < pBandCurrent->GetWidth(); x++)
            {
               double sigmaSignal = EstimateSigmaSignal( pBandCurrent, x, y, mSigmaNoise, mWindowSize );
               double w1 = pBandCurrent->GetValue(x,y);
               double w2 = pBandParent->GetValue(x/2,y/2) / scaleParentChildFactor;
               double shrinkageFactor = ComputeBivariateShrinkagefactor(w1, w2, sigmaSignal, scaleNoiseVariance );
               pBandCurrent->SetValue(x,y, shrinkageFactor * w1);
            }
         }
      }
      #ifdef DEBUG
      cout << "Average variance at scale level = " << (avgVariance) / (double)(pBandSetCurrent->GetNumberOfOrientations())
           << endl << flush;
      #endif
   }
   else
   {
      std::cerr << "PyramidDenoiser::DenoiseLevelBivariate: Cannot denoise level " << level << " since top level is " << mpPyramid->GetNumberOfScales() << std::endl << std::flush;
   }
}
Example #2
0
void PyramidDenoiser::DenoiseLevelLaplacian(int level)
{
   if (level < (int)(mpPyramid->GetNumberOfScales() - 1))
   {
      PyramidLevel<double>* pBandSet;
      if (level != -1)
      {
         pBandSet = mpPyramid->GetRecursiveScale(level);
      }
      else
      {
         pBandSet = mpPyramid->GetResidualScale();
      }

      for (int orientationIndex = 0; orientationIndex < pBandSet->GetNumberOfOrientations(); orientationIndex++)
      {
         ArrayGrid<double>* pBand = pBandSet->GetOrientedBand( orientationIndex);
         for (int y = 0; y < pBand->GetHeight(); y++)
         {
            for (int x = 0; x < pBand->GetWidth(); x++)
            {
               double sigmaSignal = EstimateSigmaSignal( pBand, x, y, mSigmaNoise, mWindowSize );
               double w1 = pBand->GetValue(x,y);
               double shrinkageFactor = ComputeLaplacianShrinkagefactor(w1, sigmaSignal, mSigmaNoise);
               mpPyramid->GetRecursiveScale( level)->GetOrientedBand( orientationIndex)->SetValue(x,y, shrinkageFactor * w1);
            }
         }
      }
   }
   else
   {
      std::cerr << "PyramidDenoiser::DenoiseLevelLaplacian: Cannot denoise level " << level << " since top level is " << mpPyramid->GetNumberOfScales() << std::endl << std::flush;
   }
}