mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-13 21:28:01 +02:00
avfilter/vf_fftdnoiz: add alternative denoising method
This commit is contained in:
parent
0914e3a14a
commit
003f9a9b41
@ -12347,6 +12347,9 @@ Set size of block in pixels, Default is 32, can be 8 to 256.
|
|||||||
@item overlap
|
@item overlap
|
||||||
Set block overlap. Default is 0.5. Allowed range is from 0.2 to 0.8.
|
Set block overlap. Default is 0.5. Allowed range is from 0.2 to 0.8.
|
||||||
|
|
||||||
|
@item method
|
||||||
|
Set denoising method. Default is @code{wiener}, can also be @code{hard}.
|
||||||
|
|
||||||
@item prev
|
@item prev
|
||||||
Set number of previous frames to use for denoising. By default is set to 0.
|
Set number of previous frames to use for denoising. By default is set to 0.
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ typedef struct FFTdnoizContext {
|
|||||||
float amount;
|
float amount;
|
||||||
int block_size;
|
int block_size;
|
||||||
float overlap;
|
float overlap;
|
||||||
|
int method;
|
||||||
int nb_prev;
|
int nb_prev;
|
||||||
int nb_next;
|
int nb_next;
|
||||||
int planesf;
|
int planesf;
|
||||||
@ -85,6 +86,12 @@ static const AVOption fftdnoiz_options[] = {
|
|||||||
OFFSET(block_size), AV_OPT_TYPE_INT, {.i64=32}, 8, 256, .flags = FLAGS },
|
OFFSET(block_size), AV_OPT_TYPE_INT, {.i64=32}, 8, 256, .flags = FLAGS },
|
||||||
{ "overlap", "set block overlap",
|
{ "overlap", "set block overlap",
|
||||||
OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0.2, 0.8, .flags = FLAGS },
|
OFFSET(overlap), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0.2, 0.8, .flags = FLAGS },
|
||||||
|
{ "method", "set method of denoising",
|
||||||
|
OFFSET(method), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, .flags = TFLAGS, "method" },
|
||||||
|
{ "wiener", "wiener method",
|
||||||
|
0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, .flags = TFLAGS, "method" },
|
||||||
|
{ "hard", "hard thresholding",
|
||||||
|
0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, .flags = TFLAGS, "method" },
|
||||||
{ "prev", "set number of previous frames for temporal denoising",
|
{ "prev", "set number of previous frames for temporal denoising",
|
||||||
OFFSET(nb_prev), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, .flags = FLAGS },
|
OFFSET(nb_prev), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, .flags = FLAGS },
|
||||||
{ "next", "set number of next frames for temporal denoising",
|
{ "next", "set number of next frames for temporal denoising",
|
||||||
@ -495,6 +502,7 @@ static void filter_plane2d(FFTdnoizContext *s, int plane,
|
|||||||
const int block = p->b;
|
const int block = p->b;
|
||||||
const int nox = p->nox;
|
const int nox = p->nox;
|
||||||
const int noy = p->noy;
|
const int noy = p->noy;
|
||||||
|
const int method = s->method;
|
||||||
const int buffer_linesize = p->buffer_linesize / sizeof(float);
|
const int buffer_linesize = p->buffer_linesize / sizeof(float);
|
||||||
const float depthx = (1 << (s->depth - 8)) * (1 << (s->depth - 8));
|
const float depthx = (1 << (s->depth - 8)) * (1 << (s->depth - 8));
|
||||||
const float sigma = s->sigma * depthx / (s->block_size * s->block_size);
|
const float sigma = s->sigma * depthx / (s->block_size * s->block_size);
|
||||||
@ -514,7 +522,15 @@ static void filter_plane2d(FFTdnoizContext *s, int plane,
|
|||||||
re = buff[j * 2 ];
|
re = buff[j * 2 ];
|
||||||
im = buff[j * 2 + 1];
|
im = buff[j * 2 + 1];
|
||||||
power = re * re + im * im;
|
power = re * re + im * im;
|
||||||
factor = fmaxf(limit, (power - sigma) / (power + 1e-15f));
|
switch (method) {
|
||||||
|
case 0:
|
||||||
|
factor = fmaxf(limit, (power - sigma) / (power + 1e-15f));
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
factor = power < sigma ? limit : 1.f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
buff[j * 2 ] *= factor;
|
buff[j * 2 ] *= factor;
|
||||||
buff[j * 2 + 1] *= factor;
|
buff[j * 2 + 1] *= factor;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user