code: public void generateForegroundEdge() {
          foregroundEdgePixels.clear();
          Point p;
          for( int n = 0; n < height; ++n ) {
              for( int m = 0; m < width; ++m ) {
                  if (pixels[m][n] == FOREGROUND) {
                      p = new Point(m, n);
                      for( int j = -1; j < 2; ++j ) {
                          for( int i = -1; i < 2; ++i ) {
                              if ((p.x + i >= 0) && (p.x + i < width) && (p.y + j >= 0)
                                      && (p.y + j < height)) {
                                  if ((pixels[p.x + i][p.y + j] == BACKGROUND)
                                          && (!foregroundEdgePixels.contains(p))) {
                                      foregroundEdgePixels.add(p);
                                  }
                              }
                          }
                      }
                  }
              }
          }
      }
docs: Generates the foreground edge hash set from the 2D array of pixels.