Example #1
0
  public void process(BufferedImage input) {
    setInputImage(input);

    image.reshape(input.getWidth(), input.getHeight());
    transform.reshape(input.getWidth(), input.getHeight());
    magnitude.reshape(input.getWidth(), input.getHeight());
    phase.reshape(input.getWidth(), input.getHeight());

    ConvertBufferedImage.convertFrom(input, image, true);
    fft.forward(image, transform);

    GDiscreteFourierTransformOps.shiftZeroFrequency(transform, true);

    GDiscreteFourierTransformOps.magnitude(transform, magnitude);
    GDiscreteFourierTransformOps.phase(transform, phase);

    // Convert it to a log scale for visibility
    GPixelMath.log(magnitude, magnitude);

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            setPreferredSize(new Dimension(image.width + 50, image.height + 20));
            processedImage = true;
          }
        });

    doRefreshAll();
  }
  /**
   * Runs a canny edge detector on the input image given the provided thresholds. If configured to
   * save a list of trace points then the output image is optional.
   *
   * <p>NOTE: Input and output can be the same instance, if the image type allows it.
   *
   * @param input Input image. Not modified.
   * @param threshLow Lower threshold. >= 0.
   * @param threshHigh Upper threshold. >= 0.
   * @param output (Might be option) Output binary image. Edge pixels are marked with 1 and
   *     everything else 0.
   */
  public void process(T input, float threshLow, float threshHigh, ImageUInt8 output) {

    if (threshLow < 0 || threshHigh < 0)
      throw new IllegalArgumentException("Threshold must be >= zero!");

    if (hysteresisMark != null) {
      if (output == null)
        throw new IllegalArgumentException(
            "An output image must be specified when configured to mark edge points");
    }

    // setup internal data structures
    blurred.reshape(input.width, input.height);
    derivX.reshape(input.width, input.height);
    derivY.reshape(input.width, input.height);
    intensity.reshape(input.width, input.height);
    suppressed.reshape(input.width, input.height);
    angle.reshape(input.width, input.height);
    direction.reshape(input.width, input.height);
    work.reshape(input.width, input.height);

    // run canny edge detector
    blur.process(input, blurred);
    gradient.process(blurred, derivX, derivY);
    GGradientToEdgeFeatures.intensityAbs(derivX, derivY, intensity);
    GGradientToEdgeFeatures.direction(derivX, derivY, angle);
    GradientToEdgeFeatures.discretizeDirection4(angle, direction);
    GradientToEdgeFeatures.nonMaxSuppression4(intensity, direction, suppressed);

    performThresholding(threshLow, threshHigh, output);
  }
Example #3
0
 /**
  * Checks to see if the target image is null or if it is a different size than the test image. If
  * it is null then a new image is returned, otherwise target is reshaped and returned.
  *
  * @param target
  * @param testImage
  * @param targetType
  * @param <T>
  * @return
  */
 public static <T extends ImageSingleBand> T checkReshape(
     T target, ImageSingleBand testImage, Class<T> targetType) {
   if (target == null) {
     return GeneralizedImageOps.createSingleBand(targetType, testImage.width, testImage.height);
   } else if (target.width != testImage.width || target.height != testImage.height) {
     target.reshape(testImage.width, testImage.height);
   }
   return target;
 }
  public void process(final BufferedImage buffLeft, final BufferedImage buffRight) {
    imageLeft.reshape(buffLeft.getWidth(), buffLeft.getHeight());
    imageRight.reshape(buffRight.getWidth(), buffRight.getHeight());
    grayLeft.reshape(buffLeft.getWidth(), buffLeft.getHeight());
    grayRight.reshape(buffRight.getWidth(), buffRight.getHeight());

    ConvertBufferedImage.convertFromMulti(buffLeft, imageLeft, true, imageType);
    ConvertBufferedImage.convertFromMulti(buffRight, imageRight, true, imageType);

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            panel.setImages(buffLeft, buffRight);
            processedImage = true;
            doRefreshAll();
          }
        });
  }
  @Override
  public void setImage(MultiSpectral<T> image) {
    gray.reshape(image.width, image.height);
    grayII.reshape(image.width, image.height);
    bandII.reshape(image.width, image.height);

    GConvertImage.average(image, gray);
    GIntegralImageOps.transform(gray, grayII);
    for (int i = 0; i < image.getNumBands(); i++)
      GIntegralImageOps.transform(image.getBand(i), bandII.getBand(i));

    alg.setImage(grayII, bandII);
  }
Example #6
0
  private void scaleUpLayers() {
    T l = pyramid.getLayer(0);
    if (upscale == null) {
      interp = (InterpolatePixelS<T>) FactoryInterpolation.nearestNeighborPixelS(l.getClass());
      upscale = (T) l._createNew(l.width, l.height);
    } else {
      upscale.reshape(l.width, l.height);
    }

    int N = pyramid.getNumLayers();

    for (int i = 0; i < N; i++) {
      new FDistort(pyramid.getLayer(i), upscale).interpNN().scaleExt().apply();
      BufferedImage b = ConvertBufferedImage.convertTo(upscale, null, true);
      if (showScales) addImage(b, String.format("%5.2f", pyramid.getScale(i)));
      else addImage(b, String.format("%5.2f", pyramid.getSigma(i)));
    }
  }
  public void process(final BufferedImage image) {
    imageInput.reshape(image.getWidth(), image.getHeight());
    imageBinary.reshape(image.getWidth(), image.getHeight());
    imageOutput.reshape(image.getWidth(), image.getHeight());

    ConvertBufferedImage.convertFromSingle(image, imageInput, imageType);

    final double threshold = GThresholdImageOps.computeOtsu(imageInput, 0, 255);
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            selectThresh.setThreshold((int) threshold);
            setInputImage(image);
            selectThresh.getHistogramPanel().update(imageInput);
            selectThresh.repaint();
          }
        });
    doRefreshAll();
  }
 @Override
 public void process(T input, ImageUInt8 output) {
   work1.reshape(input.width, input.height);
   work2.reshape(input.width, input.height);
   GThresholdImageOps.adaptiveSquare(input, output, radius, bias, down, work1, work2);
 }
  public void evaluate(String dataName, TldTracker<T, ?> tracker) {
    System.out.println("Processing " + dataName);

    String path = "data/track_rect/TLD/" + dataName;

    Rectangle2D_F64 initial = UtilTldData.parseRectangle(path + "/init.txt");
    Rectangle2D_F64 found = new Rectangle2D_F64();

    TldVisualizationPanel gui = null;

    String imageType = new File(path + "/00001.jpg").exists() ? "jpg" : "png";

    int imageNum = 0;
    while (true) {
      String imageName = String.format("%s/%05d.%s", path, imageNum + 1, imageType);
      BufferedImage image = UtilImageIO.loadImage(imageName);
      if (image == null) break;

      input.reshape(image.getWidth(), image.getHeight());
      ConvertBufferedImage.convertFrom(image, input, true);

      boolean detected;

      if (imageNum == 0) {
        gui = new TldVisualizationPanel(this);
        gui.setFrame(image);
        gui.setSelectRectangle(false);
        ShowImages.showWindow(gui, dataName);
        tracker.initialize(
            input, (int) initial.p0.x, (int) initial.p0.y, (int) initial.p1.x, (int) initial.p1.y);
        detected = true;
      } else {
        detected = tracker.track(input);
        found.set(tracker.getTargetRegion());
      }

      if (!detected) {
        System.out.println("No Detection");
      } else {
        System.out.printf(
            "Detection: %f,%f,%f,%f\n", found.p0.x, found.p0.y, found.p1.x, found.p1.y);

        Graphics2D g2 = image.createGraphics();

        int w = (int) found.getWidth();
        int h = (int) found.getHeight();

        g2.drawRect((int) found.p0.x, (int) found.p0.y, w, h);
      }

      gui.setFrame(image);
      gui.update(tracker, detected);
      gui.repaint();

      imageNum++;

      while (paused) {
        Thread.yield();
      }

      //			BoofMiscOps.pause(30);
    }
    System.out.println();
  }