C 定点数学锐化滤波器

C 定点数学锐化滤波器,c,graphics,C,Graphics,有人有一个很好的定点数学1通道锐化过滤器吗? 应该使用定点数学在C中完成 可能的声明: void sharpen( uint8_t *src, uint8_t *dest, int srcdstpitch, int height ); 编辑:“最佳算法实现获得300代表奖金”。看来你自己的问题不可能有悬赏。尽管如此,我将仔细阅读任何获奖者的答案,最多30个答案:)。您必须从中提取代码;看起来没那么难。好的,我试试看。非常简单的线性过滤器,只查看最近的邻居,但它可以工作: 编辑:更改代码以分别处

有人有一个很好的定点数学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;
        }
    }
}
/*简单的拉普拉斯锐化*/
空洞锐化(uint8_t*src、uint8_t*dest、int-width、int-height、int-strength)
{
int i,j;
在这里,北,南,西,东;
整数锐化;
静态常数int scale=1024;
/*处理内部像素*/
对于(i=1;i
我用PGM图像试过了。你可以调整磨刀的力度
使用最后一个参数。100的强度是一个很好的起点。

“锐化过滤器”通常非常难看。要执行实际的锐化,您需要一个非线性过滤器,它可以对图像执行某种扭曲。任何线性滤波器,或者仅仅是相对于目标像素的固定位置的像素值的函数的滤波器,都会给出非常难看的结果。我想我的观点是锐化是一个困难的问题,找到一个定点实现可能会更加困难……您的声明无法编译。你所说的
int srcdst pitch
是什么意思?你为什么不自己尝试一下,或者通过网络搜索来实现,或者查找,如果你遇到问题,来这里问一些具体的问题。所以,这不是一个免费的代码共享网站。@phresnel我做到了。它有一个问题-不够快。@Ulteriour:也许可以做一些关于如何使其快速的研究(从使用探查器或阅读Agner Fogs优化指南开始)。或者,尝试谷歌看看不同的实现。不幸的是,你在这里还没有足够的信誉来获得赏金;我不认为这样做是合适的……如果你追求速度,你可能想在单独的循环中处理图像的边缘。这样,内部的环路就简化了(
north=src[width*(i-1)+j];
等等)。我的测试表明这可以提高23%的速度。你能在这里更新代码吗?我愿意接受你的回答,因为我不希望有比这更好的结果。好吧,我添加了优化,并将强度作为函数的参数。PS:不要担心奖金,这只是为了好玩。看到你的贡献了-我想你应该在这里得到50k的提升,他也不会忘记许可条款。