Java - ImageFilter Simple


/ Published in: Java
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public BufferedImage Embrossing(BufferedImage bi)
  2. {
  3. BufferedImage buff = new BufferedImage(bi.getWidth(), bi.getHeight(), bi.getType());
  4.  
  5. Kernel kernel = new Kernel(3, 3, new float[] {
  6. -2f, 0f, 0f,
  7. 0f, 1f, 0f,
  8. 0f, 0f, 2f
  9. });
  10.  
  11. ConvolveOp op = new ConvolveOp(kernel);
  12. op.filter(bi, buff);
  13.  
  14. return buff;
  15. }
  16.  
  17.  
  18. public BufferedImage Blurring(BufferedImage bi)
  19. {
  20. BufferedImage buff = new BufferedImage(bi.getWidth(), bi.getHeight(), bi.getType());
  21.  
  22. Kernel kernel = new Kernel(3, 3, new float[] {
  23. 1f/9f, 1f/9f, 1f/9f,
  24. 1f/9f, 1f/9f, 1f/9f,
  25. 1f/9f, 1f/9f, 1f/9f
  26. });
  27.  
  28. ConvolveOp op = new ConvolveOp(kernel);
  29. op.filter(bi, buff);
  30.  
  31. return buff;
  32. }
  33.  
  34.  
  35. public BufferedImage Sharpening(BufferedImage bi)
  36. {
  37. BufferedImage buff = new BufferedImage(bi.getWidth(), bi.getHeight(), bi.getType());
  38.  
  39. Kernel kernel = new Kernel(3, 3, new float[] {
  40. -1f, -1f, -1f,
  41. -1f, 9f, -1f,
  42. -1f, -1f, -1f
  43. });
  44.  
  45. ConvolveOp op = new ConvolveOp(kernel);
  46. op.filter(bi, buff);
  47.  
  48. return buff;
  49. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.