summaryrefslogtreecommitdiff
path: root/Year_2/IandM/maximum
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-02-18 19:18:32 +0100
committerSanto Cariotti <santo@dcariotti.me>2021-02-18 19:18:32 +0100
commit1942f603803a92b0c2f078975a04167a6ee2f7bf (patch)
treed9d63dcce55c3f05fa94c94f4abf5f394aca2057 /Year_2/IandM/maximum
parentab0dfb9eb5c0e1d39bb2e87bb3692171585a6716 (diff)
i&m: add operators
Diffstat (limited to 'Year_2/IandM/maximum')
-rw-r--r--Year_2/IandM/maximum/data/lena.pngbin0 -> 473831 bytes
-rw-r--r--Year_2/IandM/maximum/maximum.pde31
2 files changed, 31 insertions, 0 deletions
diff --git a/Year_2/IandM/maximum/data/lena.png b/Year_2/IandM/maximum/data/lena.png
new file mode 100644
index 0000000..59ef68a
--- /dev/null
+++ b/Year_2/IandM/maximum/data/lena.png
Binary files differ
diff --git a/Year_2/IandM/maximum/maximum.pde b/Year_2/IandM/maximum/maximum.pde
new file mode 100644
index 0000000..4f0f54f
--- /dev/null
+++ b/Year_2/IandM/maximum/maximum.pde
@@ -0,0 +1,31 @@
+void setup() {
+ size(512, 256);
+ PImage img = loadImage("lena.png");
+ img.resize(256, 256);
+ img.filter(GRAY);
+
+ image(img, 0, 0);
+ image(maximum(img, 11), 256, 0);
+}
+
+PImage maximum(PImage I, int n) {
+ PImage out = createImage(I.width, I.height, RGB);
+
+ int off = n/2;
+
+ for (int x = 0; x < I.width; ++x) {
+ for (int y = 0; y < I.height; ++y) {
+ 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) {
+ tarr[i] = red(t.pixels[i]);
+ }
+
+ out.set(x, y, color(max(tarr)));
+ }
+ }
+
+ return out;
+}