Facebook
From Funky Owl, 7 Years ago, written in Java.
Embed
Download Paste or View Raw
Hits: 273
  1. PImage img = loadImage("lena2.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.     float r = red(img.pixels[pos]);
  17.     float g = green(img.pixels[pos]);
  18.     float b = blue(img.pixels[pos]);
  19.    
  20.     float r_sasiad = red(img.pixels[pos_sasiad]);
  21.     float g_sasiad = green(img.pixels[pos_sasiad]);
  22.     float b_sasiad = blue(img.pixels[pos_sasiad]);
  23.    
  24.     if (val == 0) {
  25.       r = r_sasiad;
  26.       g = g_sasiad;
  27.       b = b_sasiad;
  28.     }
  29.     else if (val == 255) {
  30.       r = r_sasiad;
  31.       g = g_sasiad;
  32.       b = b_sasiad;
  33.     }
  34.     edgeImg.pixels[y*img.width + x] = color(r,g,b);
  35.   }
  36. }
  37. edgeImg.updatePixels();
  38. image(edgeImg, w, 0);