From 1942f603803a92b0c2f078975a04167a6ee2f7bf Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Thu, 18 Feb 2021 19:18:32 +0100 Subject: i&m: add operators --- Year_2/IandM/minimum/data/lena.png | Bin 0 -> 473831 bytes Year_2/IandM/minimum/minimum.pde | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 Year_2/IandM/minimum/data/lena.png create mode 100644 Year_2/IandM/minimum/minimum.pde (limited to 'Year_2/IandM/minimum') diff --git a/Year_2/IandM/minimum/data/lena.png b/Year_2/IandM/minimum/data/lena.png new file mode 100644 index 0000000..59ef68a Binary files /dev/null and b/Year_2/IandM/minimum/data/lena.png differ diff --git a/Year_2/IandM/minimum/minimum.pde b/Year_2/IandM/minimum/minimum.pde new file mode 100644 index 0000000..b960a24 --- /dev/null +++ b/Year_2/IandM/minimum/minimum.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(minimum(img, 11), 256, 0); +} + +PImage minimum(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(min(tarr))); + } + } + + return out; +} -- cgit v1.2.3-18-g5258