Advertisement
Tims125

compsci

Apr 12th, 2019
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. /** Method to show large changes in color
  2. * @param edgeDist the distance for finding edges
  3. */
  4. public void edgeDetection(int edgeDist, boolean test)
  5. {
  6. Pixel leftPixel = null;
  7. Pixel rightPixel = null;
  8. Pixel topPixel = null;
  9. Pixel bottomPixel = null;
  10. Pixel[][] pixels = this.getPixels2D();
  11. Color rightColor = null;
  12. Color bottomColor = null;
  13. Color topColor = null;
  14. for (int row = 0; row < pixels.length; row++)
  15. {
  16. for (int col = 0;
  17. col < pixels[0].length-1; col++)
  18. {
  19. leftPixel = pixels[row][col];
  20. rightPixel = pixels[row][col+1];
  21. rightColor = rightPixel.getColor();
  22. if (leftPixel.colorDistance(rightColor) >
  23. edgeDist)
  24. leftPixel.setColor(Color.BLACK);
  25. else
  26. leftPixel.setColor(Color.WHITE);
  27. }
  28. }
  29. if(test){
  30. for (int col = 0 ; col < pixels[0].length -1;
  31. col++){
  32. for (int row = 0; row < pixels.length - 1; row++){
  33. topPixel = pixels[row][col];
  34. bottomPixel = pixels[row + 1][col];
  35. bottomColor = bottomPixel.getColor();
  36. topColor = topPixel.getColor();
  37. if(!(topColor.equals(Color.BLACK) || topColor.equals(Color.WHITE)) && !(bottomColor.equals(Color.WHITE)||bottomColor.equals(Color.BLACK) )){
  38. if (topPixel.colorDistance(bottomColor) > edgeDist) {
  39. topPixel.setColor(Color.BLACK);
  40. }else{
  41. topPixel.setColor(Color.WHITE);
  42. }
  43. }
  44. }
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement