我确实有这段代码可以使用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);
}
}
现在我想通过对这些行进行修改来将图像转换为黑白,但我真的不知道在矩阵中使用什么值以及如何对其进行卷积。
答案 0 :(得分:4)
你只需要制作一个色彩空间,然后将其传递给你的convertOP
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorConvertOp op = new ColorConvertOp(cs, null);
BufferedImage image = op.filter(image, null);