From 321b268bb74512289f9eb361560e8ceb9d30fe59 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 16 Feb 2021 21:51:54 +0100 Subject: i&m: add operations --- Year_2/IandM/stretching/data/lena.png | Bin 0 -> 473831 bytes Year_2/IandM/stretching/stretching.pde | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 Year_2/IandM/stretching/data/lena.png create mode 100644 Year_2/IandM/stretching/stretching.pde (limited to 'Year_2/IandM/stretching') diff --git a/Year_2/IandM/stretching/data/lena.png b/Year_2/IandM/stretching/data/lena.png new file mode 100644 index 0000000..59ef68a Binary files /dev/null and b/Year_2/IandM/stretching/data/lena.png differ diff --git a/Year_2/IandM/stretching/stretching.pde b/Year_2/IandM/stretching/stretching.pde new file mode 100644 index 0000000..0814190 --- /dev/null +++ b/Year_2/IandM/stretching/stretching.pde @@ -0,0 +1,32 @@ +void setup() { + size(512, 256); + PImage img = loadImage("lena.png"); + img.resize(256, 256); + img.filter(GRAY); + + image(img, 0, 0); + image(stretching(img), 256, 0); +} + +PImage stretching(PImage I) { + PImage out = I.copy(); + out.loadPixels(); + + float max = red(out.pixels[0]); + float min = max; + + for (int i = 0; i < out.pixels.length; ++i) { + float t = red(out.pixels[i]); + if (t < min) + min = t; + if (t > max) + max = t; + } + + for (int i = 0; i < out.pixels.length; ++i) { + out.pixels[i]= color(255*(red(out.pixels[i])-min)/(max-min)); + } + + out.updatePixels(); + return out; +} -- cgit v1.2.3-18-g5258