Skip to content

Commit

Permalink
added source for iion, qauto, plambda and disp_statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
carlodef committed Jun 13, 2014
0 parents commit ce594ef
Show file tree
Hide file tree
Showing 14 changed files with 6,910 additions and 0 deletions.
79 changes: 79 additions & 0 deletions colorcoords.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#ifndef _COLORCOORDS_C
#define _COLORCOORDS_C


#ifndef BAD_MIN
#define BAD_MIN(a,b) (b)<(a)?(b):(a)
#endif

static void hsv_to_rgb_doubles(double *out, double *in)
{
//assert_hsv(in);
double r, g, b, h, s, v; r=g=b=h=s=v=0;
h = in[0]; s = in[1]; v = in[2];
if (s == 0)
r = g = b = v;
else {
int H = fmod(floor(h/60),6);
double p, q, t, f = h/60 - H;
p = v * (1 - s);
q = v * (1 - f*s);
t = v * (1 - (1 - f)*s);
switch (H) {
case 6:
case 0: r = v; g = t; b = p; break;
case 1: r = q; g = v; b = p; break;
case 2: r = p; g = v; b = t; break;
case 3: r = p; g = q; b = v; break;
case 4: r = t; g = p; b = v; break;
case -1:
case 5: r = v; g = p; b = q; break;
default:
fprintf(stderr, "H=%d\n", H);
assert(false);
}
}
out[0] = r; out[1] = g; out[2] = b;
//assert_rgb(out);
}


static void rgb_to_hsv_doubles(double *out, double *in)
{
//assert_rgb(in);
double r, g, b, h, s, v, M, m;
r = in[0]; g = in[1]; b = in[2];

//printf("rgb %g,%g,%g...\n", r, g, b);

if (g >= r && g >= b) {
M = g;
m = BAD_MIN(r, b);
h = M == m ? 0 : 60*(b-r)/(M-m)+120;
}
else if (b >= g && b >= r) {
M = b;
m = BAD_MIN(r, b);
h = M == m ? 0 : 60*(r-g)/(M-m)+240;
}
else {
assert(r >= g && r >= b);
M = r;
if (g >= b) {
m = b;
h = M == m ? 0 : 60*(g-b)/(M-m)+0;
} else {
m = g;
h = M == m ? 0 : 60*(g-b)/(M-m)+360;
}
}

s = M == 0 ? 0 : (M - m)/M;
v = M;
h = fmod(h, 360);

//printf("\thsv %g,%g,%g\n", h, s, v);
out[0] = h; out[1] = s; out[2] = v;
//assert_hsv(out);
}
#endif//_COLORCOORDS_C
96 changes: 96 additions & 0 deletions disp_statistics.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include "iio.h"


int main (int argc, char **argv)
{
/* ppatameter parsing - parameters*/
if(argc<4)
{
fprintf (stderr, "too few parameters\n");
fprintf (stderr, " usage: %s DISP GT [precision=1 [DIFF]]\n\n",argv[0] );
fprintf (stderr, "Computes statistics about the disparity map(DISP), given the ground truth (GT) and a precision.");
fprintf (stderr, "\n");
fprintf (stderr, "Writes the statistics in the standard output and optionally generates a difference image (DIFF).\n");
fprintf (stderr, "The statistics are: precision(nondense), precision(dense), RMSE(nondense), L1(nondense)\n");
fprintf (stderr, "\n");
fprintf (stderr, "GT may contain NaN and INFS, these pixels will not be considered in the statistics.\n");
fprintf (stderr, "DISP may contain NaNs, for indicating that the algorithm was unable to compute a disparity (ie. non-dense).\n");
fprintf (stderr, "these pixels will not be considered in the nondense statistics.\n");
fprintf (stderr, "\n");
fprintf (stderr, "In case the inputs are multi-channel only the first channel is used.\n");
return 1;
}

int nc,nr,nch,nc2,nr2,nch2;
int N;
float *disp,*gt,*out_diff;
float precision = 1;

disp = iio_read_image_float_split(argv[1], &nc, &nr, &nch);
gt = iio_read_image_float_split(argv[2], &nc2, &nr2, &nch2);
if (nc!=nc2 || nr!=nr2) abort();
if(argc>=4) precision = atof (argv[3]);

N = nc*nr;

// allocate false positive/negative masks
out_diff = malloc(N*sizeof*out_diff);
for(int i=0;i<N;i++) out_diff[i]=0;

// only use the first channel for computing the statistics
float M_nondense=0, M=0, correct=0, l1=0, l2=0;
for(int i=0;i<N;i++)
{
float d = disp[i];
float g = gt[i];

// Do not consider the point if it is NaN or infinity in the GT
// NaN in GT indicate that there is no data there to compare with.
// Inf in GT usually is used to signal occlusion, and we are not interested in occlusions.
//
// Nan in the disparity map indicate that the algorithm was unable to compute a disparity
// almost all the statistics are computed without considering these points.
// The "correct" statistic also evaluates the completeness so the nan count as incorrect if the area is not occluded.
if( !isnan(g) )
{
float diff = fabs(d-g);
if (isinf(g) && (isnan(d) || isinf(d))) diff=0; // case of correctly detected occlusion

M++;
if(!isnan(d)) {
M_nondense++;
if(diff <= precision) correct++;
l2 += diff*diff;
l1 += diff;

out_diff[i] = g-d;
}

}

}
// compute statistics
float ratio_correct_nondense = correct/M_nondense;
float ratio_correct_dense = correct/M;
float RMSE = sqrt((float)l2 /M_nondense);
float L1 = (float)l1 /M_nondense;

printf("%f \t %f \t %f \t %f\n", ratio_correct_nondense, ratio_correct_dense, RMSE, L1);
printf("#precision\t precision complete\t RMSE\t L1\n");

// save the FP and FN masks
if(argc>=5) iio_save_image_float_split(argv[4],out_diff,nc,nr,1);

free(gt);
free(disp);
free(out_diff);

return 0;
}



84 changes: 84 additions & 0 deletions fail.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#ifndef _FAIL_C
#define _FAIL_C

#include <stdio.h>
#include <stdlib.h>

#ifdef __linux
# include <sys/types.h>
# include <unistd.h>
static const char *emptystring = "";
static const char *myname(void)
{
# define n 0x29a
//const int n = 0x29a;
static char buf[n];
pid_t p = getpid();
snprintf(buf, n, "/proc/%d/cmdline", p);
FILE *f = fopen(buf, "r");
if (!f) return emptystring;
int c, i = 0;
while ((c = fgetc(f)) != EOF && i < n) {
# undef n
buf[i] = c ? c : ' ';
i += 1;
}
if (i) buf[i-1] = '\0';
fclose(f);
return buf;
}
#else
static const char *myname(void) { return ""; }
#endif//__linux

#ifdef DOTRACE
#include <execinfo.h>
#endif

#ifndef BACKTRACE_SYMBOLS
#define BACKTRACE_SYMBOLS 50
#endif

static void print_trace(FILE *f)
{
(void)f;
#ifdef DOTRACE
void *array[BACKTRACE_SYMBOLS];
size_t size, i;
char **strings;

size = backtrace (array, BACKTRACE_SYMBOLS);
strings = backtrace_symbols (array, size);

fprintf (f, "Obtained %zu stack frames.\n", size);

for (i = 0; i < size; i++)
fprintf (f, "%s\n", strings[i]);

free (strings);
#endif
}

#include <stdarg.h>

//static void fail(const char *fmt, ...) __attribute__((noreturn,format(printf,1,2)));
static void fail(const char *fmt, ...) __attribute__((noreturn));
static void fail(const char *fmt, ...)

{
va_list argp;
fprintf(stderr, "\nFAIL(\"%s\"): ", myname());
va_start(argp, fmt);
vfprintf(stderr, fmt, argp);
va_end(argp);
fprintf(stderr, "\n\n");
fflush(NULL);
print_trace(stderr);
#ifdef NDEBUG
exit(-1);
#else//NDEBUG
exit(*(volatile int *)0x43);
#endif//NDEBUG
}

#endif//_FAIL_C
Loading

0 comments on commit ce594ef

Please sign in to comment.