开发者

Simple Image Sharpening algorithm for Android App

I am looking for a simple image sharpening algorithm to use in my Android application. I have a grayscale image captured from video (mostly used for text) and I would like to sharpen it because my phone does not have auto focus, and the close object distance blurs the text. I don't have any background in im开发者_JS百科age processing. But as a user, I am familiar with unsharp masking and other sharpening tools available in Gimp, Photoshop, etc. I didn't see any support for image processing in the Android API, and hence am looking for a method to implement myself. Thanks.


This is a simple image sharpening algorithm.

You should pass to this function width, height and byte[] array of your grayscale image and it will sharpen the image in this byte[] array.

void sharpen(int width, int height, byte* yuv) {

    char *mas;
    mas = (char *) malloc(width * height);
    memcpy(mas, yuv, width * height);

    signed int res;

    int ywidth;

    for (int y = 1; y < height - 1; y++) {
        ywidth = y * width;
        for (int x = 1; x < width - 1; x++) {
            res = (
                      mas[x + ywidth] * 5
                    - mas[x - 1 + ywidth]
                    - mas[x + 1 + ywidth]
                    - mas[x + (ywidth + width)]
                    - mas[x + (ywidth - width)]

                    );
            if (res > 255) {
                res = 255;
            };
            if (res < 0) {
                res = 0;
            };

            yuv[x + ywidth] = res;

        }
    }
    free(mas);
}


If you have access to pixel information, your most basic option woul be a sharpening convolution kernel. Take a look at the following sites, you can learn more about sharpening kernels and how to apply kernels there.

link1
link2


ImageJ has many algorithms in Java and is freely available.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜