有没有人有一个很好的定点数学1通道锐化滤波器?
应该用C语言用定点数学来完成。
可能的声明:

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

编辑:“最佳算法实现获得300次重复奖励”。似乎不可能在你自己的问题上得到赏金。不过,我会仔细检查任何一个获胜者的答案和最多30个答案:)。

最佳答案

好吧,这是我的尝试。非常简单的线性滤波器,只查看最近的邻居,但它可以工作:
编辑:更改代码以分别处理图像的边缘,
出于表演目的。使锐化的力量
函数的参数。

/* 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的力量是一个很好的起点。

关于c - 定点数学锐化过滤器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6673154/

10-11 21:05