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/stretching.pde | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Year_2/IandM/stretching/stretching.pde (limited to 'Year_2/IandM/stretching/stretching.pde') 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