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/bitplane/bitplane.pde | 39 ++++++++++++++++++++++++++++++++++++ Year_2/IandM/bitplane/data/lena.png | Bin 0 -> 473831 bytes 2 files changed, 39 insertions(+) create mode 100644 Year_2/IandM/bitplane/bitplane.pde create mode 100644 Year_2/IandM/bitplane/data/lena.png (limited to 'Year_2/IandM/bitplane') diff --git a/Year_2/IandM/bitplane/bitplane.pde b/Year_2/IandM/bitplane/bitplane.pde new file mode 100644 index 0000000..33cda9c --- /dev/null +++ b/Year_2/IandM/bitplane/bitplane.pde @@ -0,0 +1,39 @@ +int nb = 0; + +void setup() { + size(512, 256); +} + +void draw() { + PImage img = loadImage("lena.png"); + img.resize(256, 256); + img.filter(GRAY); + + image(img, 0, 0); + image(bitplane(img, nb), 256, 0); +} + +void keyPressed() { + if(key == '+' && nb < 7) { + nb++; + } else if(key == '-' && nb > 1) { + nb--; + } +} + +PImage bitplane(PImage I, int nb) { + PImage out = I.copy(); + out.loadPixels(); + + int x, r; + + for (int i = 0; i < out.pixels.length; ++i) { + x = int(red(out.pixels[i])); + r = (x >> nb) & 1; + out.pixels[i] = color(255*r); + } + + out.updatePixels(); + + return out; +} diff --git a/Year_2/IandM/bitplane/data/lena.png b/Year_2/IandM/bitplane/data/lena.png new file mode 100644 index 0000000..59ef68a Binary files /dev/null and b/Year_2/IandM/bitplane/data/lena.png differ -- cgit v1.2.3-18-g5258