Some days ago I saw in this site the algorithm below to convert color images to binary images and I used it in my application (with some small changes). However, I need to know what is the name of the implemented algorithm and, if possible, some references about it.
Thanks in advance!
public static boolean[][] createBinaryImage( Bitmap bm )
{
int[] pixels = new int[bm.getWidth()*bm.getHeight()];
bm.getPixels( pixels, 0, bm.getWidth(), 0, 0, bm.getWidth(), bm.getHeight() );
int w = bm.getWidth();
// Calculate overall lightness of image
long gLightness = 0;
int lLightness;
int c;
for ( int x = 0; x < bm.getWidth(); x++ )
{
for ( int y = 0; y < bm.getHeight(); y++ )
{
c = pixels[x+y*w];
lLightness = ((c&0x00FF0000 )>>16) + ((c & 0x0000FF00 )>>8) + (c&0x000000FF);
pixels[x+y*w] = lLightness;
gLightness += lLightness;
}
}
gLightness /= bm.getWidth() * bm.getHeight();
gLightness = gLightness * 5 / 6;
// Extract features
boolean[][] binaryImage = new boolean[bm.getWidth()][bm.getHeight()];
for ( int x = 0; x < bm.getWidth(); x++ )
for ( int y = 0; y < bm.getHeight(); y++ )
binaryImage[x][y] = pixels[x+y*w] <= gLightness;
return binaryImage;
}