`Mean`

class is a simple implementation of blurring
* an image. Mean filtering is a simple, intuitive and easy to implement
* method of smoothing images, i.e. reducing the amount of intensity
* variation between one pixel and the next. It is often used to reduce
* noise in images.
* * The idea of mean filtering is simply to replace each pixel value in * an image with the mean (`average') value of its neighbours, including * itself. This has the effect of eliminating pixel values which are * unrepresentative of their surroundings. Mean filtering is usually * thought of as a convolution filter. Like other convolutions it is * based around a kernel, which represents the shape and size of the * neighbourhood to be sampled when calculating the mean. Often a 3×3 * square kernel is used, as shown in Figure 1, although larger kernels * (e.g. 5×5 squares) can be used for more severe smoothing. (Note that * a small kernel can be applied more than once in order to produce a * similar - but not identical - effect as a single pass with a large * kernel.) * * @author Andrzej Jóźwiak * @author Stanisław Walczak * @author Konrad Jojczyk * @version 0.002, 29/06/07 * @since JDK1.5 */ public class Mean extends WindowFilter { /** * The width stores window width. */ protected int width; /** * The height stores window height. */ protected int height; /** * Creates Mean filter with a window of a given * width and height. * * @param width The window width. * @param height The window height. */ public Mean( int width, int height ) { this.width = width; this.height = height; } /** * Creates Mean filter with a window with * width and height each equal to the given parameter. * * @param size The value of width and height. */ public Mean( int size ) { this( size, size ); } /** * Creates Mean filter with a window size * 3x3. */ public Mean() { this( 3 ); } /** * This method is derived from WindowFilter. It has the implementation of * basic mean algorithm. */ protected int getNewPixelVal( TiledImage src, Point p, int channel ) { int value = 0; int count = 0; Point pIter = new Point(); for ( pIter.y = 0; pIter.y < windowHeight; pIter.y++ ) for ( pIter.x = 0; pIter.x < windowWidth; pIter.x++ ){ int val = getWindowPixelVal( src, pIter, channel ); value+=val; count++; } return value/count; } /** * Sets used window properties. */ protected void setWindowProperties() { windowWidth = width; windowHeight = height; dstPointInWindow = new Point( width/2, height/2 ); } }