Guest User

Untitled

a guest
Jul 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. double[][] smooth={{1/9.0, 1/9.0, 1/9.0},
  2. {1/9.0, 1/9.0, 1/9.0},
  3. {1/9.0, 1/9.0, 1/9.0}};
  4.  
  5. double[][] sharp={{1/9.0, 1/9.0, 1/9.0},
  6. {1/9.0, -8/9.0, 1/9.0},
  7. {1/9.0, 1/9.0, 1/9.0}};
  8.  
  9. public void filter(double[][] mat, BufferedImage img, int i, int j){
  10. int r,g,b;
  11. for(int k=-1;k<2;k++){
  12. for(int l=-1;l<2;l++){
  13. r=(int)Math.round(mat[k+1][l+1]*getR(img,i+k,j+l));
  14. g=(int)Math.round(mat[k+1][l+1]*getG(img,i+k,j+l));
  15. b=(int)Math.round(mat[k+1][l+1]*getB(img,i+k,j+l));
  16. setRGB(img2,r,g,b,i,j);
  17. }
  18. }
  19. }
  20.  
  21. public void setRGB(BufferedImage img,int r, int g, int b, int i, int j){
  22. int all= (a << 24) | (r << 16) | (g << 8) | b;
  23. img.setRGB(j,i, all);
  24. }
  25. public int getR(BufferedImage img, int i,int j){
  26. int rgb=img.getRGB(j,i);
  27. return (rgb >>>16) & 0xFF;
  28. }
  29.  
  30. public int getG(BufferedImage img, int i,int j){
  31. int rgb=img.getRGB(j,i);
  32. return (rgb >>>8) & 0xFF;
  33. }
  34. public int getB(BufferedImage img, int i,int j){
  35. int rgb=img.getRGB(j,i);
  36. return (rgb >>> 0) & 0xFF;
  37. }
  38.  
  39. public void iteratePixels(){
  40. int h = getHeight();
  41. int w = getWidth();
  42.  
  43. for(int i=0; i<h;i++){
  44. for(int j=0; j<w; j++){
  45. filter(smooth,img,i,j);
  46.  
  47.  
  48. // averageFilter(i,j);
  49.  
  50.  
  51.  
  52. }
  53. }
  54.  
  55.  
  56. }
Add Comment
Please, Sign In to add comment