-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedian_cut_vquan.cpp
80 lines (73 loc) · 2 KB
/
median_cut_vquan.cpp
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
//Copyright 2012 Anna Jezierska
#include "median_cut.h"
using namespace std;
void mcGetCodevectors (
int sData,
int nCodevectors,
double **data,
double **q
)
{
int i = 0; // counter
double *ch1 = data[0];
double *ch2 = data[1];
double *ch3 = data[2];
double *Q_val_1 = q[0];
double *Q_val_2 = q[1];
double *Q_val_3 = q[2];
Point* points = new Point[sData];
for ( i =0; i<sData; i++)
{
points[i].x[0] = ch1[i];
points[i].x[1] = ch2[i];
points[i].x[2] = ch3[i];
}
list<Point> palette = medianCut(points, sData, nCodevectors);
list<Point>::iterator iter;
i=0;
for (iter = palette.begin() ; iter != palette.end(); iter++)
{
Q_val_1[i] = (double)iter->x[0];
Q_val_2[i] = (double)iter->x[1];
Q_val_3[i] = (double)iter->x[2];
i++;
}
delete points;
}
/*
void init_q_im_media_cut (
int ps,
int Q,
double *R,
double *G,
double *B,
double *Q_val_1,
double *Q_val_2,
double *Q_val_3,
double *q_1,
double *q_2,
double *q_3
)
{
int32_t i =0, j=0, k=0;
int32_t distance = 0, d=0;
for (i=0; i<ps; i++)
{
distance = 3*pow(256,2);
for (k=0; k<Q; k++)
{
d = pow( ( R[i]- Q_val_1[k]),2)+
pow( ( G[i]- Q_val_2[k]),2)+
pow( ( B[i]- Q_val_3[k]),2);
if (d<distance)
{
distance = d;
j=k;
}
}
q_1[i]=Q_val_1[j];
q_2[i]=Q_val_2[j];
q_3[i]=Q_val_3[j];
}
}
*/