summaryrefslogtreecommitdiff
path: root/Year_2/IandM/psnr_mse/psnr_mse8365406430453607560.autosave
blob: cac2b9939e8f0bcee3a1ef48225d762fd70d3d82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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;
}