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 - Dilate3

11.04.2006
| 5611 views |
  • submit to reddit
        // pixel before the filter
// |--|--|--|
// |  |  |  |
// |--|--|--|
// |  | *|  |
// |--|--|--|
// |  |  |  |
// |--|--|--|

// pixel after the filter
// |--|--|--|
// | *| *| *|
// |--|--|--|
// | *| *| *|
// |--|--|--|
// | *| *| *|
// |--|--|--|

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