-
Notifications
You must be signed in to change notification settings - Fork 1
/
compute_cost_color.c
64 lines (51 loc) · 953 Bytes
/
compute_cost_color.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "header.h"
#include "proto.h"
double compute_cost_color(
int width,
int height,
double *image1_r,
double *image1_g,
double *image1_b,
double *image2_r,
double *image2_g,
double *image2_b,
int d,
double max_cost,
int i,
int j
)
{
double cost;
int ind1;
int ind2;
int cind;
double I1_dbl;
double I2_dbl;
double diff;
if ( (j-d) < 0 )
dmag5_error_handler("compute_cost_color");
if ( (j-d) > (width-1) )
dmag5_error_handler("compute_cost_color");
cost= 0;
ind1= i*width+j;
ind2= i*width+(j-d);
I1_dbl= image1_r[ind1];
I2_dbl= image2_r[ind2];
diff= fabs(I2_dbl-I1_dbl);
cost+= diff;
I1_dbl= image1_g[ind1];
I2_dbl= image2_g[ind2];
diff= fabs(I2_dbl-I1_dbl);
cost+= diff;
I1_dbl= image1_b[ind1];
I2_dbl= image2_b[ind2];
diff= fabs(I2_dbl-I1_dbl);
cost+= diff;
cost/= 3;
/*
Apply truncation to reduce the effect of occluded pixels
*/
if ( cost > max_cost )
cost= max_cost;
return cost;
}