-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFaces.pde
More file actions
213 lines (189 loc) · 5.9 KB
/
Copy pathFaces.pde
File metadata and controls
213 lines (189 loc) · 5.9 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import processing.javafx.*;
import ddf.minim.analysis.*;
import ddf.minim.*;
import papaya.*;
import ddf.minim.ugens.*;
import ddf.minim.spi.*; // for AudioStream
import processing.pdf.*; //for pdf export
// for the sound processing -----------------------
Minim minim;
//AudioPlayer player;
FFT fft ;
AudioOutput out;
AudioInput in;
WindowFunction newWindow = FFT.NONE;
int buffer = 1024;
float[] f_means = {0., 0. , 0.} ;
float[] f_means_old = new float[3];
int[] max_freq = new int[3];
float[] f_maxs = new float[3];
float f_diff = 0 ;
int limits[] = new int[4];
float beatmittel = 0.0;
float beatneu = 0.0;
// end variables for sound processing -----------------------
// factors that can be controlled by the keyboard -----------
//float[] factors = {0.13, 0.264 , 0.05} ;
//float newfacelimit = 2;
float[] factors = {0.031896718, 0.06477489 , 0.0122679705} ;
float newfacelimit = 0.49071875;
// factor that scale all other factors
float superfac = 1 ; // is assigned when button is pushed
boolean log_on = false;
// global variables -------------------------------------------------
Table table;
float[][] A;
float[][] phi;
float[] umean;
int Nr = 402; // number of rows
int Nc = 250; // number of columns
int Nc4 = 4*Nc;
int Nc2 = 2*Nc;
int Nfaces ;
float[][][] matrix ;
float[] u_tilde;
PImage img;
int face_id = 0;
float randfuk = 1;
int Nmodes ;
int im_position_x, im_position_y, new_imsize_x, new_imsize_y;
// ------------------------------------------------
void setup()
{
//size(1900, 1000,P2D); //FX2D or P2D
//size(1000,1000,P2D);
fullScreen(P2D,SPAN);
//translate(width/2,height/2);
//fullScreen(FX2D); //, SPAN);
noFill();
stroke(255);
background(0);
// the new size of the image for displaying
new_imsize_x = int(Nc*2.5);
new_imsize_y = int(Nr*2.5);
// calculate the position to make the image appear in the center
int mywidth = 1920;
int myheight = 1080;
im_position_x = int(mywidth/2 - new_imsize_x/2);
im_position_y = int(myheight/2 - new_imsize_y/2);
//the limits of the frequency separation
limits[0] = 1 ; // start frequency
limits[1] = buffer/200 ; //low frequencies
limits[2] = buffer/6 ; //mid frequencies
limits[3] = buffer/2 ; //high frequencies (end frequency)
println(limits);
// Create an empty image with width 2*Nc and height 2*Nr
//img = createImage(2*Nc,2*Nr, ALPHA);
img = createImage(Nc,Nr, ALPHA);
img.loadPixels(); // Load the pixel data of the image
//table = loadTable("Parameters.txt","csv");
//println(table.getRowCount());
//println(table.getColumnCount());
//A = new float[table.getRowCount()][table.getColumnCount()];
//int i = 0;
//for(TableRow row : table.rows()){
// for(int j = 0; j< table.getColumnCount(); j++){
// A[i][j] = row.getFloat(j);
// println(A[i][j]);
// }
// i++;
//}
A = ReadFile("./POD_data_BW/Parameters.txt"," ");
phi = Mat.transpose(ReadFile("./POD_data_BW/Modes.txt"," "));
umean = Mat.transpose(ReadFile("./POD_data_BW/Mean.txt"," "))[0];
println("lenght phi ");
println(phi.length);
println(phi[0].length);
println("lenght A = number of faces ");
println(A.length);
println(A[0].length);
Nfaces = A.length;
u_tilde = Mat.constant(0.0,phi[0].length);
// reshape to
//matrix = new float[Nfaces][Nr][Nc];
//for (int k = 0; k < Nfaces; k++) {
// for (int i = 0; i < Nr; i++) {
// for (int j = 0; j < Nc; j++) {
// matrix[k][i][j] = phi[k][i * Nc + j];
// }
// }
//}
//println("matrixlength");
//println(matrix.length);
//println(matrix[0].length);
//println(matrix[0][0].length);
////loadPixels();
//for (int i = 0; i < Nr; i++) {
// for (int j = 0; j < Nc; j++) {
// //int colorValue = color(phi[i][int(random(0,290))] ); // Convert to grayscale
// int c = color(matrix[0][i][j]);
// // the original pixel
// img.pixels[i*Nc*4 + 2*j ] = c;
// // the right neibour pixel
// img.pixels[i*Nc*4 + 2*j + 1 ] = c;
// // the lower neibour pixel
// img.pixels[i*Nc*4 + 2*j + 2*Nc ] = c;
// // the lower right neibour pixel
// img.pixels[i*Nc*4 + 2*j + 2*Nc + 1] = c;
// }
//}
//img.updatePixels();
////img.resize(1000,804);
//image(img,0,0);
// for the sound processing -----------------------
minim = new Minim(this);
// construct a LiveInput by giving it an InputStream from minim.
in = minim.getLineIn(); //new LiveInput( inputStream );
//
fft = new FFT( buffer, in.sampleRate() );
println(in.sampleRate());
}
/*
void keyPressed() {
if(key == 'i'){
a +=10;
}
}
*/
void draw() {
// draw an image from pixels
background(0);
// get the sound numbers ----------------------
Get_sound_numbers();
// reconstruction of the picture
if (f_diff > newfacelimit){
println("newface Id");
println(f_diff);
// choose a new face randomly
face_id = int(random(0,Nfaces));
}
Nmodes = min(5 + int(f_maxs[1]/f_means[1]*Nfaces),Nfaces);
// println(Nmodes);
// float[] rec = Reconstruct_pod(A[face_id],0,int(random(0,292)),umean[face_id],u_tilde);
float[] rec = Reconstruct_pod(A[face_id],0,Nmodes,umean[face_id],u_tilde);
for(int i = 0; i < rec.length;i++){
// set the pixel color from the matrix
img.pixels[i] = color(rec[i] + f_means[2]*random(-255,255));
}
img.updatePixels();
// img.resize(1000,500);
// show the picture
//image(img, im_position_x ,im_position_y);
// parameters c,d for size to display
image(img, im_position_x ,im_position_y, new_imsize_x, new_imsize_y);
}
void mouseWheel(MouseEvent event) {
float e = event.getCount();
println("mouse Wheel");
println(e);
randfuk += e;
println("randfuk");
println(randfuk);
}
void mousePressed() {
face_id +=1;
noLoop();
}
void mouseReleased() {
loop();
}