summaryrefslogtreecommitdiff
path: root/Year_2/IandM/minimum/minimum.pde
blob: c2057c844b35e63cd901f2a6033db8012d69120b (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
int k = 1;
void setup() {
  size(512, 256);
}

void draw() {
  PImage img = loadImage("lena.png");
  img.resize(256, 256);
  img.filter(GRAY);

  image(img, 0, 0);
  image(minimum(img, k), 256, 0);
}

void keyPressed() {
  if (key == '+') {
    k++;
  } else if (key == '-') {
    k--;
  }
}

PImage minimum(PImage I, int n) {
  PImage out = createImage(I.width, I.height, RGB);

  int off = n/2;

  for (int x = 0; x < I.width; ++x) {
    for (int y = 0; y < I.height; ++y) {
      PImage t = I.get(x-off, y-off, n, n);
      float[] tarr = new float[n*n];
      t.loadPixels();

      for (int i = 0; i < t.pixels.length; ++i) {
        tarr[i] = red(t.pixels[i]);
      }

      out.set(x, y, color(min(tarr)));
    }
  }

  return out;
}