I've written a convert Grayscale to binary code like this.
for(int x = 0; x < width; ++x) {
for(int y = 0; y < height; ++y) {
// get one pixel color
int pixel = bmpOriginal.getPixel(x, y);
int red = Color.red(pixel);
int green = Color.green(pixel);
int blue = Color.blue(pixel);
int gray = (int)(red * 0.3 + green * 0.59 + blue * 0.11);
//get binary value
if(gray < threshold){
bmpBinary.setPixel(x, y, 0xFF000000);
} else{
bmpBinary.setPixel(x, y, 0xFFFFFFFF);
}
}
}
return bmpBinary;
How can I count white pixel in binary image that I've already converted from Gray scale?
User contributions licensed under CC BY-SA 3.0