コード例 #1
0
 /**
  * All work is done in constructor.
  *
  * @param filePath path to image
  */
 public PrewittEdgeDetector(String filePath) {
   // read image and get pixels
   BufferedImage originalImage;
   try {
     originalImage = ImageIO.read(new File(filePath));
     findEdges(Grayscale.imgToGrayPixels(originalImage), false);
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
コード例 #2
0
  /**
   * Example run.
   *
   * <p>Displays detected edges next to orignal image.
   *
   * @param args
   * @throws IOException
   */
  public static void main(String[] args) throws IOException {
    // read image and get pixels
    String img = args[0];
    BufferedImage originalImage = ImageIO.read(new File(img));
    int[][] pixels = Grayscale.imgToGrayPixels(originalImage);

    // run SobelEdgeDetector
    final long startTime = System.currentTimeMillis();
    PrewittEdgeDetector sed = new PrewittEdgeDetector(pixels);
    final long endTime = System.currentTimeMillis();

    // print timing information
    final double elapsed = (double) (endTime - startTime) / 1000;
    System.out.println("Prewitt Edge Detector took " + elapsed + " seconds.");
    System.out.println("Threshold = " + sed.threshold);

    // display edges
    boolean[][] edges = sed.getEdges();
    BufferedImage edges_image = Threshold.applyThresholdReversed(edges);
    BufferedImage[] toShow = {originalImage, edges_image};
    String title = "Prewitt Edge Detector by Jason Altschuler";
    ImageViewer.showImages(toShow, title);
  }