Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double[][] smooth={{1/9.0, 1/9.0, 1/9.0},
- {1/9.0, 1/9.0, 1/9.0},
- {1/9.0, 1/9.0, 1/9.0}};
- double[][] sharp={{1/9.0, 1/9.0, 1/9.0},
- {1/9.0, -8/9.0, 1/9.0},
- {1/9.0, 1/9.0, 1/9.0}};
- public void filter(double[][] mat, BufferedImage img, int i, int j){
- int r,g,b;
- for(int k=-1;k<2;k++){
- for(int l=-1;l<2;l++){
- r=(int)Math.round(mat[k+1][l+1]*getR(img,i+k,j+l));
- g=(int)Math.round(mat[k+1][l+1]*getG(img,i+k,j+l));
- b=(int)Math.round(mat[k+1][l+1]*getB(img,i+k,j+l));
- setRGB(img2,r,g,b,i,j);
- }
- }
- }
- public void setRGB(BufferedImage img,int r, int g, int b, int i, int j){
- int all= (a << 24) | (r << 16) | (g << 8) | b;
- img.setRGB(j,i, all);
- }
- public int getR(BufferedImage img, int i,int j){
- int rgb=img.getRGB(j,i);
- return (rgb >>>16) & 0xFF;
- }
- public int getG(BufferedImage img, int i,int j){
- int rgb=img.getRGB(j,i);
- return (rgb >>>8) & 0xFF;
- }
- public int getB(BufferedImage img, int i,int j){
- int rgb=img.getRGB(j,i);
- return (rgb >>> 0) & 0xFF;
- }
- public void iteratePixels(){
- int h = getHeight();
- int w = getWidth();
- for(int i=0; i<h;i++){
- for(int j=0; j<w; j++){
- filter(smooth,img,i,j);
- // averageFilter(i,j);
- }
- }
- }
Add Comment
Please, Sign In to add comment