private short getNeighborAverage(int x, int y, byte color){
    short average = 0;
    if (x == 0){
      if (y == 0){ //handles top left corner
        average = getAverage(color,x,y,x,y+1,x+1,y,x+1,y+1);
      }
      else if (y == (getHeight() - 1)){ //bottom left corner
        average = getAverage(color,x,y,x,y-1,x+1,y,x+1,y-1);
      }
      else { //left edge
        average = getAverage(color,x,y,x,y+1,x,y-1,x+1,y,x+1,y+1,x+1,y-1);
      }
    }
    else if (x == (getWidth() - 1)){
      if (y == 0){ //top right corner
        average = getAverage(color,x,y,x,y+1,x-1,y,x-1,y+1);
      }
      else if (y == (getHeight() - 1)){ //bottom right corner
        average = getAverage(color,x,y,x,y-1,x-1,y,x-1,y-1);
      }
      else { //right edge
        average = getAverage(color,x,y,x,y-1,x,y+1,x-1,y,x-1,y+1,x-1,y-1);
      }
    }
    else if (y == 0){ //top edge
      average = getAverage(color,x,y,x+1,y,x-1,y,x,y+1,x+1,y+1,x-1,y+1);
    }
    else if (y == (getHeight() - 1)){ //bottom edge
      average = getAverage(color,x,y,x+1,y,x-1,y,x,y-1,x+1,y-1,x-1,y-1);
    }
    else { //9-neighbored pixel
      average = getAverage(color,x,y,x+1,y,x-1,y,x,y+1,x,y-1,x+1,y+1,x+1,y-1,x-1,y+1,x-1,y-1);
    }
    return average;
  }