ОК, вот моя попытка.Очень простой линейный фильтр, который смотрит только на ближайших соседей, но он работает:
Редактировать: Изменен код, чтобы обрабатывать края изображения отдельно, в целях производительности.Сделал силу повышения резкости параметра функции.
/* 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 - хорошая отправная точка.