Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Method to show large changes in color
- * @param edgeDist the distance for finding edges
- */
- public void edgeDetection(int edgeDist, boolean test)
- {
- Pixel leftPixel = null;
- Pixel rightPixel = null;
- Pixel topPixel = null;
- Pixel bottomPixel = null;
- Pixel[][] pixels = this.getPixels2D();
- Color rightColor = null;
- Color bottomColor = null;
- Color topColor = 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);
- }
- }
- if(test){
- for (int col = 0 ; col < pixels[0].length -1;
- col++){
- for (int row = 0; row < pixels.length - 1; row++){
- topPixel = pixels[row][col];
- bottomPixel = pixels[row + 1][col];
- bottomColor = bottomPixel.getColor();
- topColor = topPixel.getColor();
- if(!(topColor.equals(Color.BLACK) || topColor.equals(Color.WHITE)) && !(bottomColor.equals(Color.WHITE)||bottomColor.equals(Color.BLACK) )){
- if (topPixel.colorDistance(bottomColor) > edgeDist) {
- topPixel.setColor(Color.BLACK);
- }else{
- topPixel.setColor(Color.WHITE);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement