[FFmpeg-devel] [PATCH 1/2] avfilter/vf_nlmeans: better weighting of centered pixel
Paul B Mahol
onemda at gmail.com
Sat May 12 23:24:34 EEST 2018
Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
libavfilter/vf_nlmeans.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c
index 82e779ce85..6c9c9d312d 100644
--- a/libavfilter/vf_nlmeans.c
+++ b/libavfilter/vf_nlmeans.c
@@ -39,6 +39,7 @@
#include "video.h"
struct weighted_avg {
+ float max_weight;
float total_weight;
float sum;
};
@@ -403,6 +404,7 @@ static int nlmeans_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs
if (patch_diff_sq < s->max_meaningful_diff) {
const unsigned weight_lut_idx = patch_diff_sq * s->pdiff_lut_scale;
const float weight = s->weight_lut[weight_lut_idx]; // exp(-patch_diff_sq * s->pdiff_scale)
+ wa[x].max_weight = FFMAX(weight, wa[x].max_weight);
wa[x].total_weight += weight;
wa[x].sum += weight * src[x];
}
@@ -422,8 +424,10 @@ static void weight_averages(uint8_t *dst, ptrdiff_t dst_linesize,
for (y = 0; y < h; y++) {
for (x = 0; x < w; x++) {
// Also weight the centered pixel
- wa[x].total_weight += 1.f;
- wa[x].sum += 1.f * src[x];
+ if (!isnormal(wa[x].max_weight))
+ wa[x].max_weight = 1.f;
+ wa[x].total_weight += wa[x].max_weight;
+ wa[x].sum += src[x] * wa[x].max_weight;
dst[x] = av_clip_uint8(wa[x].sum / wa[x].total_weight);
}
dst += dst_linesize;
--
2.11.0
More information about the ffmpeg-devel
mailing list