Facebook
From Scorching Echidna, 1 Month ago, written in C++.
Embed
Download Paste or View Raw
Hits: 28
  1. int energy(Pixel** image, int x, int y, int width, int height) {
  2.     int energy = 0, energyX = 0, energyY = 0;
  3.     int rightPX = 0, rightPY = 0, leftPX = 0, leftPY = 0;
  4.     int upPX = 0, upPY = 0, downPX = 0, downPY = 0;
  5.     if (x + 1 == width){
  6.       rightPX = 0;
  7.       rightPY = y;
  8.       leftPX = x - 1;
  9.       leftPY = y;
  10.     }
  11.     else if (x == 0){
  12.       leftPX = width - 1;
  13.       leftPY = y;
  14.       rightPX = x + 1;
  15.       rightPY = y;
  16.     }
  17.     else{
  18.       leftPX = x - 1;
  19.       leftPY = y;
  20.       rightPX = x + 1;
  21.       rightPY = y;
  22.     }
  23.     int redX = (image[rightPX][rightPY].r - image[leftPX][leftPY].r) * (image[rightPX][rightPY].r - image[leftPX][leftPY].r);
  24.     int greenX = (image[rightPX][rightPY].g - image[leftPX][leftPY].g) * (image[rightPX][rightPY].g - image[leftPX][leftPY].g);
  25.     int blueX = (image[rightPX][rightPY].b - image[leftPX][leftPY].b) * (image[rightPX][rightPY].b - image[leftPX][leftPY].b);
  26.     energyX = redX + greenX + blueX;
  27.  
  28.     if (y + 1 == height){
  29.       upPX = x;
  30.       upPY = y - 1;
  31.       downPX = x;
  32.       downPY = 0;
  33.     }
  34.     else if (y == 0){
  35.       upPX = x;
  36.       upPY = height - 1;
  37.       downPX = x;
  38.       downPY = y + 1;
  39.     }
  40.     else{
  41.       upPX = x;
  42.       upPY = y - 1;
  43.       downPX = x;
  44.       downPY = y + 1;
  45.     }
  46.  
  47.     int redY = (image[downPX][downPY].r - image[upPX][upPY].r) * (image[downPX][downPY].r - image[upPX][upPY].r);
  48.     int greenY = (image[downPX][downPY].g - image[upPX][upPY].g) * (image[downPX][downPY].g - image[upPX][upPY].g);
  49.     int blueY = (image[downPX][downPY].b - image[upPX][upPY].b) * (image[downPX][downPY].b - image[upPX][upPY].b);
  50.     energyY = redY + greenY + blueY;
  51.     energy = energyX + energyY;
  52.  
  53.   return energy;
  54. }