From 28743f1803721b6d0b7dcfcc1cb07c1e58f8cc12 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Wed, 12 Feb 2020 11:25:25 +0100 Subject: [PATCH] avfilter/vf_median: implement percentile option --- doc/filters.texi | 5 +++++ libavfilter/median.h | 1 + libavfilter/vf_median.c | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/filters.texi b/doc/filters.texi index 7c25bbaf97..c2af80dd51 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -13289,6 +13289,11 @@ Set which planes to process. Default is @code{15}, which is all available planes Set vertical radius size. Default value is @code{0}. Allowed range is integer from 0 to 127. If it is 0, value will be picked from horizontal @code{radius} option. + +@item percentile +Set median percentile. Default value is @code{0.5}. +Default value of @code{0.5} will pick always median values, while @code{0} will pick +minimum values, and @code{1} maximum values. @end table @subsection Commands diff --git a/libavfilter/median.h b/libavfilter/median.h index 89ae0472b0..672607caa8 100644 --- a/libavfilter/median.h +++ b/libavfilter/median.h @@ -31,6 +31,7 @@ typedef struct MedianContext { int planes; int radius; int radiusV; + float percentile; int planewidth[4]; int planeheight[4]; diff --git a/libavfilter/vf_median.c b/libavfilter/vf_median.c index ee264e1a74..0189fabd07 100644 --- a/libavfilter/vf_median.c +++ b/libavfilter/vf_median.c @@ -60,6 +60,7 @@ static const AVOption median_options[] = { { "radius", "set median radius", OFFSET(radius), AV_OPT_TYPE_INT, {.i64=1}, 1, 127, FLAGS }, { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=0xF}, 0, 0xF, FLAGS }, { "radiusV", "set median vertical radius", OFFSET(radiusV), AV_OPT_TYPE_INT, {.i64=0},0, 127, FLAGS }, + { "percentile", "set median percentile", OFFSET(percentile), AV_OPT_TYPE_FLOAT, {.dbl=.5}, 0., 1., FLAGS }, { NULL } }; @@ -127,7 +128,7 @@ static void check_params(MedianContext *s, AVFilterLink *inlink) } } - s->t = 2 * s->radius * s->radiusV + 2 * s->radius; + s->t = (2 * s->radius * s->radiusV + s->radiusV + s->radius) * 2.f * s->percentile; } static int config_input(AVFilterLink *inlink)