change the way that interations are performed at colorize algorithm
[colorize.git] / src / colorize.c
index fe50913..4ea8616 100644 (file)
@@ -184,7 +184,8 @@ again:
  * options
  */
 
-static int in_itr_num = 5, out_itr_num = 1, quick = 0, optical_flow = 1, bright_contrast = 1, alpha_change = 1;
+static int in_itr_num = 5, out_itr_num = 10, quick = 0, optical_flow = 1, bright_contrast = 1, alpha_change = 1;
+static double target_residual_change = 0.01;
 int scale = 1, scalexyz = 999;
 static char output_prefix[256] = "";
 
@@ -234,6 +235,7 @@ static int handle_options(int argc, char **argv)
                        {"output-prefix", 1, 0, 'O'},
                        {"in-itr-num", 1, 0, 'i'},
                        {"out-itr-num", 1, 0, 'o'},
+                       {"residual-change", 1, 0, 'r'},
                        {"quick", 0, 0, 'q'},
                        {"zscale", 1, 0, 'z'},
                        {"brightness-contrast", 1, 0, 'b'},
@@ -243,7 +245,7 @@ static int handle_options(int argc, char **argv)
                        {0, 0, 0, 0},
                };
 
-               c = getopt_long(argc, argv, "hd:O:i:o:qz:b:f:s:t:", long_options, &option_index);
+               c = getopt_long(argc, argv, "hd:O:i:o:r:qz:b:f:s:t:", long_options, &option_index);
 
                if (c == -1)
                        break;
@@ -268,6 +270,10 @@ static int handle_options(int argc, char **argv)
                        out_itr_num = atoi(optarg);
                        skip_args += 2;
                        break;
+               case 'r':
+                       target_residual_change = atoi(optarg) / 100.0;
+                       skip_args += 2;
+                       break;
                case 'q':
                        quick = 1;
                        skip_args += 1;
@@ -329,8 +335,9 @@ static void print_help(const char *app)
        printf(" -h --help                           This help\n");
        printf(" -d --depth <bits>                   Save images with given color bit depth (default=%d)\n", save_depth);
        printf(" -O --output-prefix <path>/<prefix>  Store result image of a sequence using this prefix\n");
-       printf(" -i --in-itr-num <num>               Alter inner iterations (weightening count) of colorization algorithm (default=%d)\n", in_itr_num);
-       printf(" -o --out-itr-num <num>              Alter outer iterations (complete turns) of colorization algorithm (default=%d)\n", out_itr_num);
+       printf(" -i --in-itr-num <num>               Alter inner iterations (smoothing count) of colorization algorithm (default=%d)\n", in_itr_num);
+       printf(" -o --out-itr-num <num>              Set iterations (fixed turns) of colorization algorithm (default=%d)\n", out_itr_num);
+       printf(" -r --residual-change <percent>      Abort iterations if residual has reached minimum change (default=%.0f)\n", target_residual_change*100);
        printf(" -q --quick                          Use quick render, but sufaces may be colorized incomplete\n");
        printf(" -z --zscale <levels>                How many grids (staring with the finest) should be scaled in z direction to generate the next coarse grid ");
        if (scalexyz < 999)
@@ -638,7 +645,7 @@ next_sequence:
 
        if (test != FLOW_NEXT && test != FLOW_PREV && test != MARKED && test != MASK && test != MASK_COLOR && test != BC_ONLY && test != BC_IMAGE) {
                printf("Colorizing %d frames, please wait...\n", k);
-               rc = colorize(I, mI, flow, flow_i, in_itr_num, out_itr_num, quick, scalexyz, feat_names, NULL);
+               rc = colorize(I, mI, flow, flow_i, in_itr_num, out_itr_num, target_residual_change, quick, scalexyz, feat_names, NULL);
                if (rc < 0) {
                        if (k > 1)
                                printf("No memory! Use smaller frames or less frames between key frames or add more memory.");