gpt4 book ai didi

c - 定点数学锐化滤波器

转载 作者:太空宇宙 更新时间:2023-11-04 02:16:45 25 4
gpt4 key购买 nike

有人有不错的定点数学 1 channel 锐化滤波器吗?应该使用定点数学在 C 中完成。

可能的声明:

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

编辑:“最佳算法实现获得 300 代表赏金”。似乎不可能对你自己的问题 oO 有赏金。尽管如此 - 我会仔细检查所有获奖者的答案和最多 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com