1

所以我试图对使用 Java 的图像应用高斯滤波器。然而,图像根本不受过滤器的影响。我正在使用内置的卷积运算符。有人能指出我出了什么问题吗?

public static void main(String[] args) {
  File img = new File( "C:\\Users\\Aditya\\Pictures\\20130729_140153.jpg" );
  BufferedImage a = null;
  try{ 
      a= ImageIO.read( img );
  }
  catch( Exception e ){
      System.out.print( e.toString() );
      return;
  }
  BufferedImage a9 = new BufferedImage( a.getWidth() , a.getHeight() , a.getType() ); 
  float[] matrix = {
    1f/273,4f/273,7f/273,4f/273,1f/273,
    4f/273,16f/273,26f/273,16f/273,4f/273,
    7f/273,26f/273,41f/273,26f/273,7f/273,
    4f/273,16f/273,26f/273,16f/273,4f/273,
    1f/273,4f/273,7f/273,4f/273,1f/273
    };
    BufferedImageOp op = new ConvolveOp( new Kernel( 5, 5, matrix ) );
    a9 = op.filter( a, a9 );
    try{
        ImageIO.write( a9 , "jpg" ,new File( "C:\\Users\\Aditya\\Pictures\\jim.jpg" ));
    }catch( Exception e ){
        System.out.println( e );
    }
    }
}

不工作是指a和a9的图像根本没有区别。就好像他们被复制了一样!

4

1 回答 1

2

您的代码没有任何问题,我运行了它,我看到输出图像中有轻微的模糊。如果您想看到更明显的效果,请将其更改为边缘检测内核,例如使用

    float[] matrix = {
             1,  0, -1,
             0,  0,  0,
            -1,  0,  1
    };
    BufferedImageOp op = new ConvolveOp(new Kernel(3, 3, matrix));
于 2013-11-07T16:44:06.603 回答