diff options
author | Santo Cariotti <santo@dcariotti.me> | 2021-02-16 21:51:54 +0100 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2021-02-16 21:51:54 +0100 |
commit | 321b268bb74512289f9eb361560e8ceb9d30fe59 (patch) | |
tree | b5ddb9ab187a952891fc2f988fb47088fc03a5f9 /Year_2/IandM/quantization | |
parent | 67438312a69f7b7aa1fdbc27610438897791ceef (diff) |
i&m: add operations
Diffstat (limited to 'Year_2/IandM/quantization')
-rw-r--r-- | Year_2/IandM/quantization/data/lena.png | bin | 0 -> 473831 bytes | |||
-rw-r--r-- | Year_2/IandM/quantization/quantization.pde | 25 |
2 files changed, 25 insertions, 0 deletions
diff --git a/Year_2/IandM/quantization/data/lena.png b/Year_2/IandM/quantization/data/lena.png Binary files differnew file mode 100644 index 0000000..59ef68a --- /dev/null +++ b/Year_2/IandM/quantization/data/lena.png diff --git a/Year_2/IandM/quantization/quantization.pde b/Year_2/IandM/quantization/quantization.pde new file mode 100644 index 0000000..cac2b99 --- /dev/null +++ b/Year_2/IandM/quantization/quantization.pde @@ -0,0 +1,25 @@ +void setup() { + size(512, 256); + PImage img = loadImage("lena.png"); + img.resize(256, 256); + img.filter(GRAY); + + image(img, 0, 0); + image(quantization(img, 10), 256, 0); +} + +PImage quantization(PImage I, int k) { + PImage out = I.copy(); + out.loadPixels(); + int r; + + for (int i = 0; i < out.pixels.length; ++i) { + r = (int) floor((red(out.pixels[i])*k)/256); + r = int((float(r)/(k-1))*255); + + out.pixels[i] = color(r); + } + + out.updatePixels(); + return out; +} |