Android:图像噪声消除

时间:2015-08-18 15:59:04

标签: java android

如提高OCR准确性的文件中所述 https://code.google.com/p/tesseract-ocr/wiki/ImproveQuality#Noise 位图上的降噪非常重要,

我从这里引用了这段代码。

image processing to improve tesseract OCR accuracy

我修改并调试了代码,看起来像这样:

public Bitmap RemoveNoise(Bitmap bmap)
{
    for (int x = 0; x < bmap.getWidth(); x++)
    {
        for (int y = 0; y < bmap.getHeight(); y++)
        {
            int pixel = bmap.getPixel(x, y);
            if (pixel.R < 162 && pixel.G < 162 && pixel.B < 162)
                bmap.setPixel(x, y, Color.BLACK);
        }
    }

    for (int  x = 0; x < bmap.getWidth(); x++)
    {
        for (int y = 0; y < bmap.getHeight(); y++)
        {
            int pixel = bmap.getPixel(x, y);
            if (pixel.R > 162 && pixel.G > 162 && pixel.B > 162)
                bmap.setPixel(x, y, Color.WHITE);
        }
    }

    return bmap;
}

我的挑战是,在调试代码后,我在pixel.R,pixel.G和pixel.B上有错误,这就是我现在所连接的地方。 此外,这可能是一种更好的算法或方法来消除图像中的噪音。感谢

1 个答案:

答案 0 :(得分:0)

在您的代码中尝试此操作

public Bitmap RemoveNoise(Bitmap bmap) {
    for (int x = 0; x < bmap.getWidth(); x++) {
        for (int y = 0; y < bmap.getHeight(); y++) {
            int pixel = bmap.getPixel(x, y);
            int R = Color.red(pixel);
            int G = Color.green(pixel);
            int B = Color.blue(pixel);
            if (R < 162 && G < 162 && B < 162)
                bmap.setPixel(x, y, Color.BLACK);
        }
    }
    for (int  x = 0; x < bmap.getWidth(); x++) {
        for (int y = 0; y < bmap.getHeight(); y++) {
            int pixel = bmap.getPixel(x, y);
            int R = Color.red(pixel);
            int G = Color.green(pixel);
            int B = Color.blue(pixel);
            if (R > 162 && G > 162 && B > 162)
                bmap.setPixel(x, y, Color.WHITE);
        }
    }
    return bmap;
}
相关问题