Ejemplo n.º 1
0
 /**
  * Basic nonparametric usage of canny edge detector. No thresholding is used.
  *
  * @param original input image
  */
 public CCannyEdgeDetector(BufferedImage original) {
   size = new Dimension(original.getWidth(), original.getHeight());
   input = original.getData();
   image =
       new BufferedImage(
           (int) size.getWidth(), (int) size.getHeight(), BufferedImage.TYPE_INT_RGB);
   bands = original.getSampleModel().getNumBands();
 }
Ejemplo n.º 2
0
  @Override
  public void paintDone(PlanarImage image, Rectangle visibleRect, boolean synchronous, long time) {
    if (image == null) return;

    Dimension previewDimension = getSize();
    if ((previewDimension.getHeight() > 1) && (previewDimension.getWidth() > 1)) {
      this.visibleRect = visibleRect;
      currentImage = new SoftReference<PlanarImage>(image);
      preview = null;
      repaint();
    }
  }
Ejemplo n.º 3
0
  @Override
  protected BufferedImage doInBackground() {
    int x, y, b;
    int[] A = null;
    int[] sum = new int[bands], sum_x = new int[bands], sum_y = new int[bands];
    WritableRaster raster = image.getRaster();

    for (x = 0; x < size.getWidth(); x++) {
      for (y = 0; y < size.getHeight(); y++) {
        if (y == 0 || y == size.getHeight() - 1 || x == 0 || x == size.getWidth() - 1) {
          for (b = 0; b < bands; b++) {
            sum[b] = 0;
          }
        } else {
          for (b = 0; b < bands; b++) {
            A =
                input.getSamples(
                    x - 1, y - 1, CSobelOperator.matrix_size, CSobelOperator.matrix_size, b, A);
            sum_x[b] = CSobelOperator.getGx(A);
            sum_y[b] = CSobelOperator.getGy(A);
          }

          for (b = 0; b < bands; b++) {
            sum[b] = Math.abs(sum_x[b]) + Math.abs(sum_y[b]);
          }
        }
        raster.setPixel(x, y, sum);
        setProgress(
            100
                * (x * ((int) size.getHeight()) + y)
                / ((int) (size.getWidth() * size.getHeight())));
      }
    }
    image.setData(raster);
    return image;
  }