简体   繁体   中英

Processing an image for Iphone fax App

I'm looking for code which cleans up a document picture, meaning takes out shadows and 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM