I want to do convolve operation on an image using java. But the program shows a runtime error like cannot do Convolve operation on the image. I am attaching the code I have done. Please help...
import java.awt.image.*;
public class ImageOperations {
private BufferedImage image, blurredImage = null;
private int w, h;
private int rgb[];
private int red[], green[], blue[];
//private int x[],freq[];
private double prob[];
public final float [] FILTER_3x3 =
{
0.1 , 0.1 , 0.1,
0.1 , 0.4 , 0.1,
0.1 , 0.1 , 0.1
};
public ImageOperations()
{
this( null );
}
public ImageOperations( BufferedImage image )
{
this.image = image;
}
public BufferedImage getImage()
{
return image;
}
public void setImageDetails()
{
w = image.getWidth();
h = image.getHeight();
}
public void getImagePixelData( BufferedImage im )
{
rgb = new int[ w * h ];
red = new int[ w * h ];
green = new int[ w * h ];
blue = new int[ w * h ];
rgb = im.getRGB(0, 0, w, h, rgbs, 0, w);
}
public void showImageData()
{
for(int i = 0; i < rgb.length; i++)
{
int tmp = rgb[i];
red[i] = (tmp & 0x00ff0000) >> 16;
green[i] = (tmp & 0x0000ff00) >> 8;
blue[i] = (tmp & 0x000000ff);
//System.out.printf ( "Red[%d] = %d, Green[%d] = %d, Blue[%d] = %d \n" , i, red[i], i , green[i], i, blue[i] );
}
System.out.println( "Image Width & Height is :: " +w+ " " +h );
}
public BufferedImage getBlurredImage()
{
ConvolveOp cop = new ConvolveOp( new Kernel( 3, 3, FILTER_3x3), ConvolveOp.EDGE_NO_OP, null) );
if(getImage() == null)
System.out.println( "Image is null");
else
System.out.println( "Image is not null");
blurredImage = cop.filter( image, blurredImage); // I'm a bit confused here
return blurredImage;
}
}