I'm looking for code which cleans up a document picture, meaning takes out shadows an开发者_StackOverflow中文版d other noises and turns it into a simple black & white image (black-the writing, white-the background).
Maybe a simple pixel algorithm will be helpful such as: dividing the image into rectangles, for each defining the most frequent scale as background and and the darker pixels as the actual writing lines.
Any help will be highly appreciated.
The problem is the code does not distinct between a letter and a shadow. every dark pixel will be black regardless of its context.
The required outcome should filter out noises such as shadows into a clear black & white image.
get the pixel data using this question
to turn each pixel into black and white add the red green and blue components together, and divide by 3. you then assign the resulting value to each pixel. now to remove noise you set a threshold vale that you want to consider noise, so for instance you could say any pixes which are above the value 200, turn them white (set to 255) and pixesl darker set them to black (0)
// turn to black and white
red = pixelData[index + 0];
green = pixelData[index + 1];
blue = pixelData[index + 2];
int combinedValue = (red + blue + green)/3;
// filter out noise
if(combinedValue >200)
{
combinedValue = 255;
}
else
{
combinedValue =0;
}
// set pixels to new value
pixelData[index + 0] = combinedValue;
pixelData[index + 1] = combinedValue;
pixelData[index + 2] = combinedValue;
精彩评论