From patchwork Fri May 11 17:49:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 8923 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp963540jad; Fri, 11 May 2018 10:50:15 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqKaiaGpfY+C17YhD6yHos0nxvY13elvAOSqXyUHFPSoCVPYwHZRp8C11iMBNsEpTId04qa X-Received: by 2002:adf:b78b:: with SMTP id s11-v6mr5042703wre.247.1526061015220; Fri, 11 May 2018 10:50:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526061015; cv=none; d=google.com; s=arc-20160816; b=zdmSc6bOskiGV/SlGq+n7RWmKJ/Zb+RdAWhMsCDsEb1eLB6IB/mHcp6uc+GqM2NWXt 6R5HKmUfqtvaZb/MDQmVC8x4vWYmm4cLUA0c3d9O2nftJfakcGnGUg48PPnZeMjseFCp Ut5Vd+NQsRIdi1jLFYOdhqtXzDNTKtOZGIXi8ifeAXEPbT6dEeL8GFrqDlkk96Tb8Ke3 M41X1kyxAkkE3OJiR64CrDKSkV8e9NFa53t+PAqwvUHOQKekYSaFhEo46o2civYUgRvU a/JdgQwIkExLaj+r5c5awwmKkNVzxSESMR7Dt1u/n5a+gdyBWtCVpunmDEA47PMHma+B 0mqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=659RH0OwTjQjcJKS/dfLud+mgK+sqY62wne+Ghxw8rw=; b=gIiR80f0cSxGYyQtWUM1Txxgux1mtj1K/LenikuyJuRismYZzCxxLUJL+SftbtjbM0 ZTm+lKdz+PowzPThWOMj7/8TqdE8T2G8znosj+c4Z/QWeciCZem8TMo+dtlB/2LPw43a b6hyExyslfjDRt+CJT2rUwPeCPOMUQwJ+dNFcAYMUdcPgDdJUNEgDhss8w68yBZ4CTb4 Z43Kyw+/Lzaagn7ipBDQj7BGrUYcgWrjnNkgVQGf30UAplqX4qEF21BA+tZ1+9/PmbEA ZaSwzo3P4JicsNT2neC5WwgZRmsSTjwEB504VFzJTMcG1f1cnjtS4SxqK7KS/IMi7BaN 61cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=e+Vk67Zi; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w72-v6si1187954wmd.116.2018.05.11.10.50.14; Fri, 11 May 2018 10:50:15 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=e+Vk67Zi; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B6DAB68A965; Fri, 11 May 2018 20:49:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 23A1968A940 for ; Fri, 11 May 2018 20:49:29 +0300 (EEST) Received: by mail-wr0-f194.google.com with SMTP id 94-v6so6121719wrf.5 for ; Fri, 11 May 2018 10:50:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=e7aKpAHleigDpRbJBzEHHsPeOtvPnoJx+GBefOKI0jQ=; b=e+Vk67Ziv1wgWFl8l3wFQPPE7BLIj8Qm5FJT/gZPIvSArRmbr2lJeSZ/ZOiYMBEEsL QPbM0/geQHhoqbLEQdCeOVZTGNPH/SQ3IVzDoN8LWgMd6EJ2xEiQLH3OEwSY7fgr6nmI +rBtNxxYgIrao50vr7GmoXikQ1wYuRCP+ECzBI3+zgDecOJRe3TWifB+lXVH1W8xRrHA SJWO8ALjnH6dM7B+l+KR8jUfGfx0CKd/BI0vAYB6M1o00jXP5t/7hkD+jDJZhEqiUi/K 7hOmfA8QFUs3Fe5nORhLvw2ZnVBDcA+jwzohJYHdb8idO7MpCMvX/+BDnh1oJMLstLQ+ ofHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=e7aKpAHleigDpRbJBzEHHsPeOtvPnoJx+GBefOKI0jQ=; b=ko97gKMU53y9VErq0vKU2g0NU2k5FKTBGBGTSEw//V3m5E4zKM1kA3bDzSOa87kuQI mzR60wFXohmvo6v7Wlh8rgRCxYgcU6Wd7gWlL60KY37TyZb33xLLadGu/hQAxPykmqh4 xl0oUJ01VJQWp/7nJ6OM4aAkUfohl1+p3XHgWgcrU0q9kGpZo/ssScbmqUQjwZ54Gp1U 7l6fO9nLDGvtuLIOYZIGBd8mxAjQxWZpt0+eyPzfqgVzKQoJWUka56W5cu4ekKs0NEea XtkLiSqKSnbcNsgl0ZoWaYGUlsBrn+KnrPmexQVHPGIUzFv8+ofv5tSI8PBmLBTsTE8r jo/w== X-Gm-Message-State: ALKqPwfoJHrQNBx6O8Ndj6rzjvYHXIguGXrt9TuWtLxhnp4ZT0MqipB3 Ob2/T1c29DI+TESk9NEgS68FZQ== X-Received: by 2002:adf:c328:: with SMTP id n37-v6mr2627wrf.91.1526061005252; Fri, 11 May 2018 10:50:05 -0700 (PDT) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id l37-v6sm5466314wrl.83.2018.05.11.10.50.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 11 May 2018 10:50:04 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Fri, 11 May 2018 19:49:45 +0200 Message-Id: <20180511174945.10801-1-onemda@gmail.com> X-Mailer: git-send-email 2.11.0 Subject: [FFmpeg-devel] [PATCH] avfilter/vf_nlmeans: add parameter to control weight of centered pixel X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- libavfilter/vf_nlmeans.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavfilter/vf_nlmeans.c b/libavfilter/vf_nlmeans.c index 82e779ce85..872fa90e28 100644 --- a/libavfilter/vf_nlmeans.c +++ b/libavfilter/vf_nlmeans.c @@ -52,6 +52,7 @@ typedef struct NLMeansContext { int chroma_w, chroma_h; double pdiff_scale; // invert of the filtering parameter (sigma*10) squared double sigma; // denoising strength + float amount; // amount of denoising int patch_size, patch_hsize; // patch size and half size int patch_size_uv, patch_hsize_uv; // patch size and half size for chroma planes int research_size, research_hsize; // research size and half size @@ -76,6 +77,7 @@ static const AVOption nlmeans_options[] = { { "pc", "patch size for chroma planes", OFFSET(patch_size_uv), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 99, FLAGS }, { "r", "research window", OFFSET(research_size), AV_OPT_TYPE_INT, { .i64 = 7*2+1 }, 0, 99, FLAGS }, { "rc", "research window for chroma planes", OFFSET(research_size_uv), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 99, FLAGS }, + { "a", "denoising amount", OFFSET(amount), AV_OPT_TYPE_FLOAT, { .dbl = 1.0 }, 0.01, 1.0, FLAGS }, { NULL } }; @@ -415,15 +417,15 @@ static int nlmeans_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs static void weight_averages(uint8_t *dst, ptrdiff_t dst_linesize, const uint8_t *src, ptrdiff_t src_linesize, struct weighted_avg *wa, ptrdiff_t wa_linesize, - int w, int h) + int w, int h, float amount) { int x, y; 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]; + wa[x].total_weight += amount; + wa[x].sum += amount * src[x]; dst[x] = av_clip_uint8(wa[x].sum / wa[x].total_weight); } dst += dst_linesize; @@ -470,7 +472,7 @@ static int nlmeans_plane(AVFilterContext *ctx, int w, int h, int p, int r, } weight_averages(dst, dst_linesize, src, src_linesize, - s->wa, s->wa_linesize, w, h); + s->wa, s->wa_linesize, w, h, 1.f / s->amount); return 0; }