Exemplo n.º 1
0
  @Override
  public BufferedImage doTransform(BufferedImage src, BufferedImage dest) {
    if (radius.getValue() == 0) {
      return src;
    }

    if (filter == null) {
      filter = new GaussianFilter();
    }

    filter.setRadius(radius.getValueAsFloat());
    filter.setPremultiplyAlpha(false);

    dest = filter.filter(src, dest);

    if (hpSharpening.isChecked()) {
      dest = ImageUtils.getHighPassSharpenedImage(src, dest);
    }

    return dest;
  }
  @Override
  protected double[] readInput() {

    // read image
    byte[] imageBinary = null;
    synchronized (video) {
      Variant varImage = video.getImageRemote(NAME);
      Variant varImageElement = varImage.getElement(6);
      imageBinary = varImageElement.toBinary();
    }

    // create pattern
    double[] pattern = new double[ORIGINAL_WIDTH * ORIGINAL_HEIGHT * BITS_PER_PIXEL];
    for (int i = 0; i < pattern.length; i++) {
      int unsignedByte = imageBinary[i] & 0xFF;
      pattern[i] = unsignedByte / 255.0;
    }

    // create image
    BufferedImage image = getBufferedImage(pattern, ORIGINAL_WIDTH, ORIGINAL_HEIGHT, 255);

    // resize image
    BufferedImage imageResized = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, image.getType());
    Graphics g = imageResized.getGraphics();
    ((Graphics2D) g)
        .setRenderingHint(
            RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.drawImage(image, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null);
    image = imageResized;

    // blur image
    BufferedImage imageBlurred = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, image.getType());
    GAUSSIAN_FILTER.filter(image, imageBlurred);
    image = imageBlurred;

    // process image
    pattern = imageProcessorRGB.processImageRGB(image);

    // set input pattern
    patternInput = pattern;

    if (!cbLearn.isSelected()) {
      return null;
    }
    return pattern;
  }