Blur an image using 3x3 Gaussian kernel?

34,169

You don't need to divide it to 9 parts. At least, I don't see a good reason to do this.

But you'd better be careful during this process, remember to copy image data to somewhere and always use this data for computation for new image, avoid to use new image data to compute new image.


Also, I don't understand why you need to write your own function to Gaussian blur a image. This can be easily be done as follows:

float[] matrix = {
    1/16f, 1/8f, 1/16f, 
    1/8f, 1/4f, 1/8f, 
    1/16f, 1/8f, 1/16f, 
};

BufferedImageOp op = new ConvolveOp( new Kernel(3, 3, matrix) );
blurredImage = op.filter(sourceImage, destImage);
Share:
34,169
Admin
Author by

Admin

Updated on July 05, 2022

Comments

  • Admin
    Admin almost 2 years

    I want to create a method to blur a 24 bit image using 3x3 Gaussian kernel.

    I was given the following things.

    The 3x3 Gaussian kernel:

    http://i.stack.imgur.com/YAEQR.png

    A is the original image and B is the resulting image.

    B(i,j) =
    1/16 * A(i-1,j-1) +1/8 * A(i,j-1) +1/16 * A(i+1,j-1) +1/8 * A(i-1,j) +1/4 * A(i,j) +1/8 *A(i+1,j) +1/16 * A(i-1,j+1) +1/8 * A(i,j+1) +1/16 * A(i+1,j+1)  
    

    The method:

    public static BufferedImage gaussianBlur(Image img)
    

    where img is a reference variable of an input image.
    The returned value is an address of an object of the resulting image.

    Should I divided the image into 9 parts to implement this method?