-
Notifications
You must be signed in to change notification settings - Fork 0
/
identifycolor.c
86 lines (72 loc) · 2.46 KB
/
identifycolor.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "final.h"
static double synaptic_weights[3];
//defSW;
double red(double ar[]) {
srand(1);
synaptic_weights[0] = 2 * (double)rand()/RAND_MAX - 1;
synaptic_weights[1] = 2 * (double)rand()/RAND_MAX - 1;
synaptic_weights[2] = 2 * (double)rand()/RAND_MAX - 1;
double training_set_inputs[4][3] = { {1, 0, 0},
{0, 1, 0}, // R - G - B
{0, 0, 1},
{1, 1, 1}
};
double training_set_outputs[4] = {1,0,0,1};
train(training_set_inputs, training_set_outputs, 1000);
//printf("Percent red: %lf \n", 100*analyze(ar));
return 100*analyze(ar);
}
double green (double ar[]){
srand(1);
synaptic_weights[0] = 2 * (double)rand()/RAND_MAX - 1;
synaptic_weights[1] = 2 * (double)rand()/RAND_MAX - 1;
synaptic_weights[2] = 2 * (double)rand()/RAND_MAX - 1;
double training_set_inputs[4][3] = { {1, 0, 0},
{0, 1, 0}, // R - G - B
{0, 0, 1},
{1, 1, 1}
};
double training_set_outputs[4] = {0,1,0,1};
train(training_set_inputs, training_set_outputs, 1000);
//printf("Percent green: %lf \n", 100*analyze(ar));
return 100*analyze(ar);
}
double blue (double ar[]) {
srand(1);
synaptic_weights[0] = 2 * (double)rand()/RAND_MAX - 1;
synaptic_weights[1] = 2 * (double)rand()/RAND_MAX - 1;
synaptic_weights[2] = 2 * (double)rand()/RAND_MAX - 1;
double training_set_inputs[4][3] = { {1, 0, 0},
{0, 1, 0}, // R - G - B
{0, 0, 1},
{1, 1, 1}
};
double training_set_outputs[4] = {0,0,1,1};
train(training_set_inputs, training_set_outputs, 1000);
//printf("Percent blue: %lf \n", 100*analyze(ar));
return 100*analyze(ar);
}
void rgb (double ar[],char *res) {
FILE *result;
// printf("%lf %lf %lf\n", ar[0], ar[1], ar[2]);
double tr, tg, tb;
tr = red(ar);
tg = green(ar);
tb = blue(ar);
// double tt = tr + tg + tb;
// tr = tr / tt;
// tg = tg / tt;
// tb = tb / tt;
// printf(RED "Percent red: %lf\n" RESET, tr);
printf("Percent red: %lf\n", tr);
// printf(GREEN "Percent green: %lf\n" RESET, tg);
printf("Percent green: %lf\n", tg);
// printf(BLUE "Percent blue: %lf\n" RESET, tb);
printf("Percent blue: %lf\n", tb);
printf("*\n");
result = fopen(res,"a");
fprintf(result,"%lf\n",tr);
fprintf(result,"%lf\n",tg);
fprintf(result,"%lf\n",tb);
fclose(result);
}