Example #1
0
 /**
  * Method to show large changes in color
  *
  * @param edgeDist the distance for finding edges
  */
 public void edgeDetection(int edgeDist) {
   Pixel leftPixel = null;
   Pixel rightPixel = null;
   Pixel[][] pixels = this.getPixels2D();
   Color rightColor = null;
   for (int row = 0; row < pixels.length; row++) {
     for (int col = 0; col < pixels[0].length - 1; col++) {
       leftPixel = pixels[row][col];
       rightPixel = pixels[row][col + 1];
       rightColor = rightPixel.getColor();
       if (leftPixel.colorDistance(rightColor) > edgeDist) leftPixel.setColor(Color.BLACK);
       else leftPixel.setColor(Color.WHITE);
     }
   }
   // code to improve edge detection
   Pixel topPixel = null;
   Pixel bottomPixel = null;
   Color bottomColor = null;
   for (int col = 0; col < pixels[0].length; col++) {
     for (int row = 0; row < pixels.length - 1; row++) {
       topPixel = pixels[row][col];
       bottomPixel = pixels[row + 1][col];
       bottomColor = bottomPixel.getColor();
       if (topPixel.colorDistance(bottomColor) > edgeDist) {
         topPixel.setColor(Color.BLACK);
       } else {
         topPixel.setColor(Color.WHITE);
       }
     }
   }
 }
Example #2
0
 /**
  * Method to show large changes in color
  *
  * @param edgeDist the distance for finding edges
  */
 public void edgeDetection(int edgeDist) {
   Pixel leftPixel = null;
   Pixel rightPixel = null;
   Pixel[][] pixels = this.getPixels2D();
   Color rightColor = null;
   for (int row = 0; row < pixels.length; row++) {
     for (int col = 0; col < pixels[0].length - 1; col++) {
       leftPixel = pixels[row][col];
       rightPixel = pixels[row][col + 1];
       rightColor = rightPixel.getColor();
       if (leftPixel.colorDistance(rightColor) > edgeDist
           || (row + 1 > pixels.length
               && leftPixel.colorDistance(pixels[row + 1][col].getColor()) > edgeDist))
         leftPixel.setColor(Color.BLACK);
       else leftPixel.setColor(Color.WHITE);
     }
   }
 }