DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Java - ImageFilter Simple

10.31.2006
| 8329 views |
  • submit to reddit
        // Filtro Embrossing
	public BufferedImage Embrossing(BufferedImage bi)
	{
		BufferedImage buff = new BufferedImage(bi.getWidth(), bi.getHeight(), bi.getType());
		
		Kernel kernel = new Kernel(3, 3, new float[] {
														-2f, 0f, 0f, 
														 0f, 1f, 0f, 
														 0f, 0f, 2f
													 });
		
		ConvolveOp op = new ConvolveOp(kernel);
		op.filter(bi, buff);
		
		return buff;
	}

// Filtro Blurring
	public BufferedImage Blurring(BufferedImage bi)
	{
		BufferedImage buff = new BufferedImage(bi.getWidth(), bi.getHeight(), bi.getType());
		
		Kernel kernel = new Kernel(3, 3, new float[] {
														1f/9f, 1f/9f, 1f/9f, 
														1f/9f, 1f/9f, 1f/9f, 
														1f/9f, 1f/9f, 1f/9f
													 });
		
		ConvolveOp op = new ConvolveOp(kernel);
		op.filter(bi, buff);
		
		return buff;
	}
	
// Filtro Sharpening
	public BufferedImage Sharpening(BufferedImage bi)
	{
		BufferedImage buff = new BufferedImage(bi.getWidth(), bi.getHeight(), bi.getType());
		
		Kernel kernel = new Kernel(3, 3, new float[] {
														-1f, -1f, -1f, 
														-1f,  9f, -1f, 
														-1f, -1f, -1f
													 });
		
		ConvolveOp op = new ConvolveOp(kernel);
		op.filter(bi, buff);
		
		return buff;
	}