diff mbox

[FFmpeg-devel,GSOC,1/2] lavfi/vf_colorconstancy: changing options ranges

Message ID 31bc06cb-c06c-1157-d592-d7f9ab4fc850@gmail.com
State New
Headers show

Commit Message

Mina Aug. 12, 2018, 11:59 p.m. UTC
Hi,

   This patch changes the maximum value for minknorm to a more sane 
value and fixes check for sigma value when difford > 0. It also 
itroduces some minor cosmetic edits(spaces and so).

Thanks.

Comments

Thilo Borgmann Aug. 13, 2018, 10:04 a.m. UTC | #1
> Am 13.08.2018 um 01:59 schrieb Mina <minas.gorgy@gmail.com>:
> 
> Hi,
> 
>   This patch changes the maximum value for minknorm to a more sane value and fixes check for sigma value when difford > 0.

> It also itroduces some minor cosmetic edits(spaces and so).

These cosmetics should come in a seperate patch to have a distinction between cosmetics and actual code changes...

Ok otherwise. Applying soon and will split it locally before that. 

-Thilo

> <0001-lavfi-vf_colorconstancy-changing-options-ranges.patch>
Thilo Borgmann Aug. 14, 2018, 6:58 p.m. UTC | #2
Am 13.08.18 um 12:04 schrieb Thilo Borgmann:
> 
> 
>> Am 13.08.2018 um 01:59 schrieb Mina <minas.gorgy@gmail.com>:
>>
>> Hi,
>>
>>   This patch changes the maximum value for minknorm to a more sane value and fixes check for sigma value when difford > 0.
> 
>> It also itroduces some minor cosmetic edits(spaces and so).
> 
> These cosmetics should come in a seperate patch to have a distinction between cosmetics and actual code changes...
> 
> Ok otherwise. Applying soon and will split it locally before that. 

Pushed as two commits.

-Thilo
diff mbox

Patch

From 8f4270e4aad285a8652e1831e828439cdb13620a Mon Sep 17 00:00:00 2001
From: Mina <minasamy_@hotmail.com>
Date: Mon, 13 Aug 2018 01:29:28 +0200
Subject: [PATCH 1/2] lavfi/vf_colorconstancy: changing options ranges

Signed-off-by: Mina <minasamy_@hotmail.com>
---
 doc/filters.texi                |  6 +++---
 libavfilter/vf_colorconstancy.c | 20 ++++++++++----------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index d6c15837f2..267bd04a43 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -9955,13 +9955,13 @@  The order of differentiation to be applied on the scene. Must be chosen in the r
 
 @item minknorm
 The Minkowski parameter to be used for calculating the Minkowski distance. Must
-be chosen in the range [0,65535] and default value is 1. Set to 0 for getting
+be chosen in the range [0,20] and default value is 1. Set to 0 for getting
 max value instead of calculating Minkowski distance.
 
 @item sigma
 The standard deviation of Gaussian blur to be applied on the scene. Must be
-chosen in the range [0,1024.0] and default value = 1. Sigma can't be set to 0
-if @var{difford} is greater than 0.
+chosen in the range [0,1024.0] and default value = 1. floor( @var{sigma} * break_off_sigma(3) )
+can't be euqal to 0 if @var{difford} is greater than 0.
 @end table
 
 @subsection Examples
diff --git a/libavfilter/vf_colorconstancy.c b/libavfilter/vf_colorconstancy.c
index 7194688dfa..e3bb39e51b 100644
--- a/libavfilter/vf_colorconstancy.c
+++ b/libavfilter/vf_colorconstancy.c
@@ -28,7 +28,6 @@ 
  * J. van de Weijer, Th. Gevers, A. Gijsenij "Edge-Based Color Constancy".
  */
 
-#include "libavutil/bprint.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
@@ -42,6 +41,8 @@ 
 
 #define GREY_EDGE "greyedge"
 
+#define SQRT3 1.73205080757
+
 #define NUM_PLANES    3
 #define MAX_DIFF_ORD  2
 #define MAX_META_DATA 4
@@ -145,7 +146,7 @@  static int set_gauss(AVFilterContext *ctx)
         sum1 = 0.0;
         for (i = 0; i < filtersize; ++i) {
             s->gauss[1][i] = - (GINDX(filtersize, i) / pow(sigma, 2)) * s->gauss[0][i];
-            sum1 += s->gauss[1][i] *GINDX(filtersize, i);
+            sum1 += s->gauss[1][i] * GINDX(filtersize, i);
         }
 
         for (i = 0; i < filtersize; ++i) {
@@ -595,7 +596,6 @@  static int diagonal_transformation(AVFilterContext *ctx, void *arg, int jobnr, i
     ThreadData *td = arg;
     AVFrame *in = td->in;
     AVFrame *out = td->out;
-    double sqrt3 = pow(3.0, 0.5);
     int plane;
 
     for (plane = 0; plane < NUM_PLANES; ++plane) {
@@ -610,7 +610,7 @@  static int diagonal_transformation(AVFilterContext *ctx, void *arg, int jobnr, i
         unsigned i;
 
         for (i = slice_start; i < slice_end; ++i) {
-            temp = src[i] / (s->white[plane] * sqrt3);
+            temp = src[i] / (s->white[plane] * SQRT3);
             dst[i] = av_clip_uint8((int)(temp + 0.5));
         }
     }
@@ -657,12 +657,12 @@  static int config_props(AVFilterLink *inlink)
     double sigma = s->sigma;
     int ret;
 
-    if (!sigma && s->difford) {
-        av_log(ctx, AV_LOG_ERROR, "Sigma can't be set to 0 when difford > 0.\n");
+    if (!floor(break_off_sigma * sigma + 0.5) && s->difford) {
+        av_log(ctx, AV_LOG_ERROR, "floor(%f * sigma) must be > 0 when difford > 0.\n", break_off_sigma);
         return AVERROR(EINVAL);
     }
 
-    s->filtersize = 2 * floor(break_off_sigma * s->sigma + 0.5) + 1;
+    s->filtersize = 2 * floor(break_off_sigma * sigma + 0.5) + 1;
     if (ret=set_gauss(ctx)) {
         return ret;
     }
@@ -735,9 +735,9 @@  static const AVFilterPad colorconstancy_outputs[] = {
 #if CONFIG_GREYEDGE_FILTER
 
 static const AVOption greyedge_options[] = {
-    { "difford",  "set differentiation order", OFFSET(difford),  AV_OPT_TYPE_INT,    {.i64=1},   0,   2,      FLAGS },
-    { "minknorm", "set Minkowski norm",        OFFSET(minknorm), AV_OPT_TYPE_INT,    {.i64=1},   0,   65535,  FLAGS },
-    { "sigma",    "set sigma",                 OFFSET(sigma),    AV_OPT_TYPE_DOUBLE, {.dbl=1},   0.0, 1024.0, FLAGS },
+    { "difford",  "set differentiation order", OFFSET(difford),  AV_OPT_TYPE_INT,    {.i64=1}, 0,   2,      FLAGS },
+    { "minknorm", "set Minkowski norm",        OFFSET(minknorm), AV_OPT_TYPE_INT,    {.i64=1}, 0,   20,     FLAGS },
+    { "sigma",    "set sigma",                 OFFSET(sigma),    AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0.0, 1024.0, FLAGS },
     { NULL }
 };
 
-- 
2.17.0