forked from sift-images/sift-images.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
combinatrix_color_pde.pde
153 lines (129 loc) · 3.65 KB
/
combinatrix_color_pde.pde
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import java.util.*;
//input parameters:
int subSize = 20;
int depth = 6; // depth is the size of transform matrix that is stored
int rows = 2;
int cols = 2;
//color rendering:
float[][] image = new float[depth*cols*3][depth*rows];
int pix;
int add = 40;
int mult = 2;
//dctIII; old matrix = T. computes x,y (variables are switched but it works)
public float[][] dct(float[][] input) {
float[][] transform = new float[subSize][subSize];
for (int u=0; u<subSize; u++) {
for (int v=0; v<subSize; v++) {
float scale;
transform[u][v] = 0;
float hold = 0;
//x, y < subSize is full-strength (applies all basis images); 1,1 is min
for (int x=0; x<depth; x++) {
for (int y=0; y<depth; y++) {
if (x == 0) {
if (y == 0) {
scale = .5;
}
else {
scale = pow(2,-.5);
}
}
else {
if (y != 0) {
scale = 1;
}
else {
scale = pow(2,-.5);
}
}
hold = cos((2*u+1)*x*PI/2/subSize)*cos((2*v+1)*y*PI/2/subSize)*scale*input[x][y]/4;
transform[u][v] += hold;
}
}
}
}
return transform;
}
int padTop;
int padLeft;
void setup() {
frameRate(20);
size(400, 400);
pix = height / rows / subSize;
noStroke();
for (int x=0;x<cols*depth*3;x++) {
for (int y=0;y<rows*depth;y++) {
image[x][y] = int(random(-3,3));
//println("col,row = ",x,y);
//println(eights[x][y],x,y);
}
}
background(0);
}
void draw() {
noStroke();
//pull from image[0,0...depth] for R[O,O]
//pull from image[0,1] for G , [o,2] for blue
int flipX, flipY;
int xShift, yShift;
//these are metarows and cols
for (int row=0;row<rows;row++) {
if (row == 0) {
flipY = 1;
yShift = width/2;
} else {
flipY = -1;
yShift = width/2*(subSize-1)/subSize;
}
for (int col=0;col<cols;col++) {
if (col == 0) {
flipX = -1;
xShift = width/2*(subSize-1)/subSize;
} else {
flipX = 1;
xShift = col*pix*subSize;
}
float tempBlockR[][] = new float[depth][depth];
float tempBlockG[][] = new float[depth][depth];
float tempBlockB[][] = new float[depth][depth];
float r[][] = new float[subSize][subSize];
float g[][] = new float[subSize][subSize];
float b[][] = new float[subSize][subSize];
for (int i=0;i<depth;i++) {
for (int j=0;j<depth;j++) {
tempBlockR[i][j] = image[3*col*depth+i][row*depth+j];
//println("R= image[",3*col*depth+i,row*depth+j,"]= ",image[3*col*depth+i][row*depth+j]);
tempBlockG[i][j] = image[3*col*depth+i+depth][row*depth+j];
//println("G= image[",3*col*depth+i+depth,row*depth+j,"]= ",image[3*col*depth+i+depth][row*depth+j]);
tempBlockB[i][j] = image[3*col*depth+i+2*depth][row*depth+j];
//println("B= image[",3*col*depth+i+2*depth,row*depth+j,"]= ",image[3*col*depth+i+2*depth][row*depth+j]);
}
}
r = dct(tempBlockR);
//println("R=",r[0][0]);
g = dct(tempBlockG);
//println("G=",g[0][0]);
b = dct(tempBlockB);
//println("B=",b[0][0]);
//println("R=",r[0][0]);
for (int i=0;i<subSize;i++) {
for (int j=0;j<subSize;j++) {
//println("R",i,j,"=",r[i][j]);
//println("G",i,j,"=",g[i][j]);
//println("B",i,j,"=",b[i][j]);
fill(to_color(r[i][j]), to_color(g[i][j]), to_color(b[i][j]));
rect(i*pix*flipX+xShift,j*pix*flipY+yShift,pix,pix);
}
}
}
}
for (int x=0;x<depth*cols*3;x++) {
for (int y=0;y<depth*rows;y++) {
image[x][y] = (image[x][y] + random(0,2)) % 38 - 1.05;
//println(x,y,"updated in image to: ",image[x][y]);
}
}
}
int to_color(float x) {
return Math.max(Math.min(255, (x+add)*mult), 0)
}