Programming/JAVA
[BufferedImage] 이미지 이진화(Image Binarize)
빈쿵바라기
2022. 9. 16. 09:50
private void binarize(BufferedImage image) {
for (int i = 0; i < image.getWidth(); i++)
for (int j = 0; j < image.getHeight(); j++)
image.setRGB(i, j, gamma(image.getRGB(i, j)) > 127 ? Color.white.getRGB() : Color.black.getRGB());
}
private int gamma(int rgb) {
return (red(rgb) + green(rgb) + blue(rgb)) / 3;
}
private int red(int rgb) {
return (rgb >> 16) & 0x000000FF;
}
private int green(int rgb) {
return (rgb >> 8) & 0x000000FF;
}
private int blue(int rgb) {
return (rgb) & 0x000000FF;
}