简体   繁体   English

为 Iphone 传真 App 处理图像

[英]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.要将每个像素变成黑色和白色,将红色绿色和蓝色分量相加,然后除以 3。然后将结果值分配给每个像素。 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)现在要消除噪声,您可以设置要考虑噪声的阈值,例如,您可以说任何高于 200 的像素,将它们变为白色(设置为 255)并将像素变暗设置为黑色(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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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