简体   繁体   English

如何使用BufferedImageOp在图像上应用黑白滤镜?

[英]How to apply black and white filter on image using BufferedImageOp?

I do have this code to increase the sharpness of the image using BufferedImageOp 我确实有这段代码使用BufferedImageOp来提高图像的清晰度

class DecreaseSharpenFilter implements MyFilter{
    public BufferedImage processImage(BufferedImage image) {
        float[] decreaseSharpnessMatrix = {0.0f, +1.0f, 0.0f, +1.0f , -5.0f, +1.0f, 0.0f, +1.0f, 0.0f };
         BufferedImageOp DecreaseSharpenFilter = new ConvolveOp(new Kernel(3, 3, decreaseSharpnessMatrix),
                    ConvolveOp.EDGE_NO_OP, null);
                return DecreaseSharpenFilter.filter(image, null);
    }
}

Now I want to convert image to black and white by doing modifications to these lines but I don't really know what values to use in the matrix and how to convolve it. 现在,我想通过对这些行进行修改来将图像转换为黑白图像,但是我真的不知道在矩阵中使用什么值以及如何对其进行卷积。

You just need to make a colorspace, then pass it in to your convertOP 您只需要创建一个色彩空间,然后将其传递给您的convertOP

ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);  
ColorConvertOp op = new ColorConvertOp(cs, null);
BufferedImage image = op.filter(image, null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM