Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.image.BufferedImage;
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.util.Arrays;
  6.  
  7. import javax.imageio.ImageIO;
  8. import javax.swing.SingleSelectionModel;
  9.  
  10. public class mean7x7 {
  11.  
  12.  
  13.  
  14.  
  15. public static void meanFilter(BufferedImage img ) throws IOException{
  16. int avg1=0;
  17. int avg2=0;
  18. int avg3=0;
  19.  
  20.  
  21.  
  22.  
  23. for (int i = 3;i<img.getWidth()-3;i++){
  24. for (int j=3;j<img.getHeight()-3;j++){
  25. for (int k=i-3;k<i+4;k++){
  26. for (int l=j-3;l<i+4;l++){
  27.  
  28. Color c = new Color(img.getRGB(k,l));
  29. avg1+= c.getRed();
  30. avg2+=c.getGreen();
  31. avg3+=c.getBlue();
  32. }
  33.  
  34. }
  35. avg1=avg1/49;
  36. avg2=avg2/49;
  37. avg3=avg3/49;
  38.  
  39. img.setRGB(i,j,new Color(avg1,avg2,avg3).getRGB());
  40. avg1=0;
  41. avg2=0;
  42. avg3=0;
  43. }
  44.  
  45. }
  46. File File = new File ("butterfly_22476-copy.png");
  47. ImageIO.write(img, "png", File);
  48.  
  49. }
  50. public static void main (String [] args) throws IOException {
  51. BufferedImage img=ImageIO.read (new File ("butterfly_22476.png"));
  52.  
  53. meanFilter(img);
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement