입력으로 bufferedImage를 사용하고 모든 검은 색 (R < 32, G < 32, B < 32)을 검정색으로 매핑하고 다른 색상을 흰색으로 매핑하는 프로그램을 작성하려고합니다. OCR (OCR 엔진은 BufferedImage를 입력으로 사용합니다). 픽셀을 반복하지 않고도이를 수행 할 수 있습니까? BlackWhiteColorModel이Java BufferedImage 맵 색상
public class BlackWhiteColorModel extends ColorModel {
public BlackWhiteColorModel(int bits) {
super(bits);
}
@Override
public int getRed(int pixel) {
int[] rgb = getRgb(pixel);
if (rgb[0] < 32 && rgb[1] < 32 && rgb[2] < 32) {
return 0;
} else {
return 255;
}
}
@Override
public int getGreen(int pixel) {
int[] rgb = getRgb(pixel);
if (rgb[0] < 32 && rgb[1] < 32 && rgb[2] < 32) {
return 0;
} else {
return 255;
}
}
@Override
public int getBlue(int pixel) {
int[] rgb = getRgb(pixel);
if (rgb[0] < 32 && rgb[1] < 32 && rgb[2] < 32) {
return 0;
} else {
return 255;
}
}
@Override
public int getAlpha(int pixel) {
return pixel;
}
private int[] getRgb(int pixel) {
int r = (pixel) & 0xFF;
int g = (pixel >> 8) & 0xFF;
int b = (pixel >> 16) & 0xFF;
int a = (pixel >> 24) & 0xFF;
return new int[]{r, g, b, a};
}
}
그러나, 나는 isCompatibleRasterException와 끝까지로 정의되는 경우 은 즉, 나는
public static BufferedImage BlackAndWhite(BufferedImage image) {
ColorModel model = new BlackWhiteColorModel(DataBuffer.TYPE_INT);
WritableRaster raster = image.getRaster();
BufferedImage newImage = new BufferedImage(model, raster, false, null);
return newImage;
}
을 시도했다. 아무도 내게 약간의 조언을 줄 수 있습니까?
당신이 필요하십니까이다 더 많은 일을 할 경우 특히 ** 블랙 & 화이트 * * 이미지 또는 ** GrayScale ** 하나? – STaefi