public static BufferedImage averageBlur(BufferedImage image, int Nwidth) {
      int width  = image.getWidth();
      int height = image.getHeight();
      
      BufferedImage temp = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
      
      for(int x = 0; x < width; x++) {
         for(int y = 0; y < height; y++) {
            int sum = 0;
            int count = 0;
            
            for(int h = x-Nwidth/2; h < x+Nwidth/2; h++) {
               if(h < 0 || h >= width) {
                  continue;
               }
               
               for(int i = y-Nwidth/2; i < y+Nwidth/2; i++) {
                  if(i < 0) {
                     continue;
                  }
                  else if(i >= height) {
                     break;
                  }
                  
                  sum += image.getRGB(h, i) & 0x000000FF;
                  count++;
               }
            }
            
            int newPVal = sum/count;
                             
            int result = 0;
            result = result | 0xFF000000;
            result = result | (newPVal << 16);
            result = result | (newPVal << 8);
            result = result | (newPVal);
            
            temp.setRGB(x, y, result);
         }
      }
      
      return temp;
   }