title: Non Local Means (NLMeans) denoising algorithm implementation
body: <p>I'm having a problem while trying to implement the NLMEANS algorithm using this <a href="http://bengal.missouri.edu/~kes25c/nl2.pdf" rel="nofollow">paper</a>.
  The output image is completely dark for the area where I'm applying the algorithm. 
  For the image input and output i'm using a framework called diblook-vs10. </p>
  
  <p>Here is my source code:</p>
  
  <pre><code>void CDibView::OnProcessingNl()
  {
  // TODO: Add your command handler code here
  
  
  int mat[400][400];
  int dif[8];
  for(int i=0;i&lt;400;i++)
      for(int j=0;j&lt;400;j++)
          mat[i][j]=0;
  
  BEGIN_PROCESSING();     
  
  BYTE red,green,blue;
  
  for(int r=dwHeight-2;r&gt;=0;r--)
      {    
           for(int c=1;c&lt;dwWidth-1;c++){
  
             mat[r][c]=lpSrc[r*w+c];
           }
      }
  
  
  
  float z=0; // Z(i)
  float nlVi=0.0; // NL[V](i)
  
  for(int i=100;i&gt;=0;i--) // searching for grey level similarities
      for(int j=1;j&lt;100;j++)
      {   
          float num=0.0; // 
            for(int r=100;r&gt;=0;r--)   
            { 
             for(int c=1;c&lt;100;c++){ 
  
                  dif[0]=mat[i][j+1]-mat[r][c+1];  
                  dif[1]=mat[i-1][j+1]-mat[r-1][c+1];
                  dif[2]=mat[i-1][j]-mat[r-1][c];
                  dif[3]=mat[i-1][j-1]-mat[r-1][c-1];
                  dif[4]=mat[i][j-1]-mat[r][c-1];
                  dif[5]=mat[i+1][j-1]-mat[r+1][c-1];
                  dif[6]=mat[i+1][j]-mat[r+1][j];
                  dif[7]=mat[i+1][j+1]-mat[r+1][c+1];
  
  
                  dif[0]=dif[0]*dif[0];  // || V(Ni) - V(Nj) || ^ 2
                  dif[1]=dif[1]*dif[1];
                  dif[2]=dif[2]*dif[2];
                  dif[3]=dif[3]*dif[3];
                  dif[4]=dif[4]*dif[4];
                  dif[5]=dif[5]*dif[5];
                  dif[6]=dif[6]*dif[6];
                  dif[7]=dif[7]*dif[7];
  
                  int sum=0;
                  float sume=0.0;
                  float eLaDif=0.0;
                  for(int cont=0;cont&lt;=7;cont++)
                  {
                      float putere=0.0;
                      putere=((float) dif[cont])/4;   //h=4 
                      eLaDif=exp(-putere);
                      sume=sume+eLaDif;
                  } 
  
                   float varweight=sume; 
  
                   num=num+varweight*mat[r][c];
                   z=z+varweight;       
             }
  
        }
        nlVi=num/z;
        lpDst[i*w+j]= nlVi;
  
  }
  END_PROCESSING("NL_MEANS");
  }
  </code></pre>