定点数学锐化滤波器

时间:2011-07-13 01:31:10

标签: c graphics

有没有人有一个很好的定点数学1通道锐化滤波器? 应该使用定点数学在C中完成。

可能的声明:

void sharpen( uint8_t *src, uint8_t *dest, int srcdstpitch, int height );

编辑:“最佳算法实现获得300个代表赏金”。似乎不可能在你自己的问题上获得赏金oO。尽管如此 - 我会仔细检查任何获奖者的答案和30个答案:)。

2 个答案:

答案 0 :(得分:2)

好的,这是我的尝试。非常简单的线性过滤器,只查看最近的邻居,但它可以工作:

编辑:更改代码以分别处理图像的边缘, 出于性能目的。制作锐化的力量a 函数的参数。

/* Simple Laplacian sharpening. */
void sharpen(uint8_t *src, uint8_t *dest, int width, int height, int strength)
{
    int i, j;
    int here, north, south, west, east;
    int sharpening;
    static const int scale = 1024;

    /* Handle interior pixels. */
    for (i = 1; i < height-1; i++) for (j = 1; j < width-1; j++) {

        /* This pixel and it's neighbors. */
        here = src[width*i+j];
        north = src[width*(i-1)+j];
        south = src[width*(i+1)+j];
        west = src[width*i+(j-1)];
        east = src[width*i+(j+1)];

        /* Filter. */
        sharpening = 4 * here - (north + south + west + east);
        here += strength * sharpening / scale;

        /* Store clipped result. */
        dest[width*i+j] = here<0 ? 0 : here>255 ? 255 : here;
    }

    /* Optimization: handle edges separately. */
    for (i = 0; i < height; i++) {
        int j_step = (i==0 || i==height-1) ? 1 : width-1;

        for (j = 0; j < width; j += j_step) {

            /* Expand the image by symmetry. */
            north = i==0 ? src[width*(1)+j] : src[width*(i-1)+j];
            south = i==height-1 ? src[width*(height-2)+j] : src[width*(i+1)+j];
            west = j==0 ? src[width*i+(1)] : src[width*i+(j-1)];
            east = j==width-1 ? src[width*i+(width-2)] : src[width*i+(j+1)];

            /* Same as the code for the interior. */
            here = src[width*i+j];
            sharpening = 4 * here - (north + south + west + east);
            here += strength * sharpening / scale;
            dest[width*i+j] = here<0 ? 0 : here>255 ? 255 : here;
        }
    }
}

我用PGM图像试了一下。您可以调整锐化的强度 用最后一个参数。强度为100是一个很好的起点。

答案 1 :(得分:1)

您必须从this gimp plug-in中提取代码;看起来并不那么难。