Facebook
From Capacious Cassowary, 1 Year ago, written in Java.
Embed
Download Paste or View Raw
Hits: 50
  1. PImage img = loadImage("lena3.bmp");
  2. int w = img.width;
  3. int h = img.height;
  4. size(2*w,h);
  5. image(img, 0, 0);  
  6. img.loadPixels();
  7. PImage edgeImg = createImage(img.width, img.height, RGB);
  8. for (int y = 1; y < img.height-1; y++) {
  9.   for (int x = 1; x < img.width-1; x++) {
  10.     float sum = 0;
  11.     int pos = x + y*img.height;
  12.     int pos_sasiad = (x+1) + y*img.height;
  13.     float val = red(img.pixels[pos]);
  14.     float val_sasiad = red(img.pixels[pos_sasiad]);
  15.    
  16.     if (val == 0) {
  17.       val = val_sasiad;
  18.     }
  19.     else if (val == 255) {
  20.       val = val_sasiad;
  21.     }
  22.     edgeImg.pixels[y*img.width + x] = color(val);
  23.   }
  24. }
  25. edgeImg.updatePixels();
  26. image(edgeImg, w, 0);