-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage_Processing.pde
More file actions
128 lines (87 loc) · 3.27 KB
/
Image_Processing.pde
File metadata and controls
128 lines (87 loc) · 3.27 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
//save the program and put the images in the created directory
//i.e., Documents>Processing>Image_Processing
PImage me = loadImage("_______.jpg");
size(me.width, me.height);
background(0);
//image(me, 0, 0);
//reconstruction controls
//noise spread; larger = more spread
int noiseMul = 60;
//determines centering. noiseMul/center: e.g., 10/2 results in +/-5 around noise value
int centerNoise = 2;
//jitter controls
//noise spread; larger = more spread
int pixelMul = 100;
//determines centering. pixelMul/center: e.g., 10/2 results in +/-5 around noise value
int pixelCenter = 2;
//number of pixels to be grabbed in the array
int pixelNum = int(random(1800));
//number of iterations over the two processes
int globalRunNum = 4;
//number of pixel subsets grabbed from orignial image
int subsetGrabbed = 500;
//number of iterations to jitter sequences of pixels
int pixelJitterRunNum =0;
//largest height to select from
int heightMax = 750;
//largest width to select from
int widthMax = 750;
float[][] kernal = { { .11, .11, .11 }, { .11, .66, .11 }, { .11, .11, .11 } };
for (int currentRun = 0; currentRun < globalRunNum; currentRun++) {
println(currentRun);
for (int i = 0; i < subsetGrabbed; i++) {
int xRand = int(random(me.width));
int yRand = int(random(me.height));
int randHeight = int(random(heightMax));
int randWidth = int(random(widthMax));
int xPerlinNoise = (int(noise(random(10))*noiseMul))-(noiseMul*centerNoise);
int yPerlinNoise = (int(noise(random(10))*noiseMul))-(noiseMul*centerNoise);
//filter(GRAY);
tint(255, 20);
//"watercolor" version
copy(me, xRand, yRand, randWidth, randHeight, xRand, yRand, (randWidth+xPerlinNoise), (randHeight+yPerlinNoise));
//glitch version
//copy(me, xRand, yRand, randWidth, randHeight, (xRand+xPerlinNoise), (yRand+yPerlinNoise), randWidth, randHeight);
}
save("reconstruction.jpg");
PImage recon = loadImage("reconstruction.jpg");
recon.loadPixels();
loadPixels();
int count = recon.width*recon.height;
for (int j = 0; j < pixelJitterRunNum; j++) {
int randStart = int(random(count));
int arrayJitter = int(noise(random(10))*pixelMul)-(pixelMul*pixelCenter);
for (int i = 0; i < pixelNum; i++) {
int pixelIncrement = (randStart+i)%count;
int pixelJitterWrap = (randStart+i+arrayJitter)%count;
if (pixelJitterWrap < 0) {
pixelJitterWrap = pixelJitterWrap + count;
}
pixels[pixelIncrement] = pixels[pixelJitterWrap%count];
}
}
updatePixels();
save("jitterReconstruction.jpg");
me = loadImage("jitterReconstruction.jpg");
}
PImage edgeImg = createImage(me.width, me.height, RGB);
int count = me.width*me.height;
for (int y = 0; y < me.height-1; y++) {
for (int x = 0; x < me.width-1; x++) {
float sum = 0;
for(int ky = -1; ky <= 1; ky++) {
for (int kx = -1; kx <= 1; kx++) {
int pos = (y + ky)*width + (x +kx);
if (pos < 0) {
pos = pos+count;
}
float val = red(me.pixels[pos%count]);
sum += kernal[ky+1][kx+1] * val;
}
}
edgeImg.pixels[y*me.width +x] = color(sum);
}
}
edgeImg.updatePixels();
image(edgeImg, 0, 0);
save("convolutionReconstruction.jpg");