Here you can find the source of filterSmooth(BufferedImage img)
public static BufferedImage filterSmooth(BufferedImage img) throws Exception
//package com.java2s; //License from project: Apache License import java.awt.Color; import java.awt.image.BufferedImage; public class Main { public static BufferedImage filterSmooth(BufferedImage img) throws Exception { final int SSIZE = 3; int x, y, i, j, val; int r;// w ww . java 2 s . c o m final int w = img.getWidth(); final int h = img.getHeight(); final BufferedImage newImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { newImg.setRGB(x, y, img.getRGB(x, y)); } } for (y = SSIZE / 2; y < h - SSIZE / 2; y++) { for (x = SSIZE / 2; x < w - SSIZE / 2; x++) { val = 0; for (i = 0; i < SSIZE; i++) { for (j = 0; j < SSIZE; j++) { final Color color = new Color(img.getRGB(x + j - SSIZE / 2, y + i - SSIZE / 2)); r = color.getRed(); val += r; } } i = val / (SSIZE * SSIZE); newImg.setRGB(x, y, new Color(i, i, i).getRGB()); } } /* Remove border */ for (y = 0; y < h; y++) { newImg.setRGB(0, y, newImg.getRGB(1, y)); newImg.setRGB(w - 1, y, newImg.getRGB(w - 2, y)); } for (x = 0; x < w; x++) { newImg.setRGB(x, 0, newImg.getRGB(x, 1)); newImg.setRGB(x, h - 1, newImg.getRGB(x, h - 2)); } return newImg; } }