public void applyMaxMask(int Rad)
 {
  int maxv; 
  int sumR=0,sumG=0,sumB=0;
  short maxR=0,maxG=0,maxB=0;

  double cc=(2*Rad+1)*(2*Rad+1)-1;
  if (!im_done) return;
  Graphics gg=cv.getGraphics();

  for (int x=Rad;x<wi-Rad;x++)
   for (int y=Rad;y<he-Rad;y++)
  {
   gg.setColor(Color.white);
   gg.drawLine(x,y,x+1,y);

  maxv=-1;
  maxR=0;maxG=0;maxB=0;
  sumR=0;sumG=0;sumB=0;
  for (int i=-Rad;i<=Rad;i++)
  for (int j=-Rad;j<=Rad;j++)
   //if (i!=0 || j!=0)
    {
      sumR=R[(y+i)*wi+(x+j)];
      sumG=G[(y+i)*wi+(x+j)];
      sumB=B[(y+i)*wi+(x+j)];
      if (sumR+sumG+sumB >= maxv)
      { maxv=sumR+sumG+sumB;
        maxR=(short)sumR;
        maxG=(short)sumG;
        maxB=(short)sumB;
      }
    }
   if (maxv>-1){
   resR[y*wi+x]=maxR;
   resG[y*wi+x]=maxG;
   resB[y*wi+x]=maxB;
   } else
   {
   resR[y*wi+x]=R[y*wi+x];
   resG[y*wi+x]=G[y*wi+x];
   resB[y*wi+x]=B[y*wi+x];
   }
   gg.setColor(new Color(resR[y*wi+x], resG[y*wi+x], resB[y*wi+x]));
   gg.drawLine(x,y,x,y);
  }
 }