summaryrefslogtreecommitdiff
path: root/Year_2
diff options
context:
space:
mode:
Diffstat (limited to 'Year_2')
-rw-r--r--Year_2/IandM/maximum/maximum.pde15
-rw-r--r--Year_2/IandM/median/median.pde25
-rw-r--r--Year_2/IandM/minimum/minimum.pde20
3 files changed, 49 insertions, 11 deletions
diff --git a/Year_2/IandM/maximum/maximum.pde b/Year_2/IandM/maximum/maximum.pde
index 4f0f54f..69d69db 100644
--- a/Year_2/IandM/maximum/maximum.pde
+++ b/Year_2/IandM/maximum/maximum.pde
@@ -1,11 +1,24 @@
+int k = 1;
+
void setup() {
size(512, 256);
+}
+
+void draw() {
PImage img = loadImage("lena.png");
img.resize(256, 256);
img.filter(GRAY);
image(img, 0, 0);
- image(maximum(img, 11), 256, 0);
+ image(maximum(img, k), 256, 0);
+}
+
+void keyPressed() {
+ if (key == '+') {
+ k++;
+ } else if (key == '-') {
+ k--;
+ }
}
PImage maximum(PImage I, int n) {
diff --git a/Year_2/IandM/median/median.pde b/Year_2/IandM/median/median.pde
index 856e50e..a6fbbac 100644
--- a/Year_2/IandM/median/median.pde
+++ b/Year_2/IandM/median/median.pde
@@ -1,11 +1,24 @@
+int k = 1;
+
void setup() {
size(512, 256);
+}
+
+void draw() {
PImage img = loadImage("lena.png");
img.resize(256, 256);
img.filter(GRAY);
image(img, 0, 0);
- image(median(img, 11), 256, 0);
+ image(median(img, k), 256, 0);
+}
+
+void keyPressed() {
+ if (key == '+') {
+ k++;
+ } else if (key == '-') {
+ k--;
+ }
}
PImage median(PImage I, int n) {
@@ -18,17 +31,17 @@ PImage median(PImage I, int n) {
PImage t = I.get(x-off, y-off, n, n);
float[] tarr = new float[n*n];
t.loadPixels();
-
- for(int i = 0; i < t.pixels.length; ++i) {
+
+ for (int i = 0; i < t.pixels.length; ++i) {
tarr[i] = red(t.pixels[i]);
}
-
+
tarr = sort(tarr);
float med = tarr[(n*n)/2];
- if((n*n)%2 == 0) {
+ if ((n*n)%2 == 0) {
med = (med+tarr[(n*n)/2-1])/2;
}
-
+
out.set(x, y, color(med));
}
}
diff --git a/Year_2/IandM/minimum/minimum.pde b/Year_2/IandM/minimum/minimum.pde
index b960a24..c2057c8 100644
--- a/Year_2/IandM/minimum/minimum.pde
+++ b/Year_2/IandM/minimum/minimum.pde
@@ -1,11 +1,23 @@
+int k = 1;
void setup() {
size(512, 256);
+}
+
+void draw() {
PImage img = loadImage("lena.png");
img.resize(256, 256);
img.filter(GRAY);
image(img, 0, 0);
- image(minimum(img, 11), 256, 0);
+ image(minimum(img, k), 256, 0);
+}
+
+void keyPressed() {
+ if (key == '+') {
+ k++;
+ } else if (key == '-') {
+ k--;
+ }
}
PImage minimum(PImage I, int n) {
@@ -18,11 +30,11 @@ PImage minimum(PImage I, int n) {
PImage t = I.get(x-off, y-off, n, n);
float[] tarr = new float[n*n];
t.loadPixels();
-
- for(int i = 0; i < t.pixels.length; ++i) {
+
+ for (int i = 0; i < t.pixels.length; ++i) {
tarr[i] = red(t.pixels[i]);
}
-
+
out.set(x, y, color(min(tarr)));
}
}