/**
   * Compares two wavelet transformations while ignoring the input image borders. Input borders
   * affect the borders of internal segments inside the transformation.
   */
  private void equalsTranHorizontal(
      WaveletDescription<?> desc,
      ImageSingleBand input,
      ImageSingleBand expected,
      ImageSingleBand found) {
    int w = expected.width;
    int h = expected.height;

    int lowerBorder = UtilWavelet.borderForwardLower(desc.getInverse().getInnerCoefficients());
    int upperBorder =
        input.width
            - UtilWavelet.borderForwardUpper(desc.getInverse().getInnerCoefficients(), input.width);

    equalsTranHorizontal(
        expected.subimage(0, 0, w / 2, h),
        found.subimage(0, 0, w / 2, h),
        lowerBorder / 2,
        upperBorder / 2,
        "left");
    equalsTranHorizontal(
        expected.subimage(w / 2, 0, w, h),
        found.subimage(w / 2, 0, w, h),
        lowerBorder / 2,
        upperBorder / 2,
        "right");
  }
Ejemplo n.º 2
0
  @Override
  public void wrap(ImageSingleBand image) {
    interpolate.setImage((T) image);

    inputWidth = image.getWidth();
    inputHeight = image.getHeight();
  }
  private synchronized void setLevel(int level) {
    //		System.out.println("level "+level);
    if (level > 0) {

      ImageSingleBand small = ss.getLayer(level - 1);
      ImageSingleBand enlarge =
          GeneralizedImageOps.createSingleBand(
              small.getClass(), ss.getInputWidth(), ss.getInputHeight());
      DistortImageOps.scale(small, enlarge, TypeInterpolate.NEAREST_NEIGHBOR);

      // if the size isn't the same null it so a new image will be declared
      if (levelImage != null
          && (levelImage.getWidth() != enlarge.width || levelImage.getHeight() != enlarge.height)) {
        levelImage = null;
      }
      levelImage = ConvertBufferedImage.convertTo(enlarge, levelImage);

      double scale = ss.getScale(level - 1);
      levelPoints.clear();
      for (ScalePoint p : points) {
        if (p.scale == scale) {
          levelPoints.add(p);
        }
      }
    } else {
      levelPoints.clear();
      levelPoints.addAll(points);
    }

    this.activeLevel = level;
  }
  private void equalsTranVertical(
      WaveletDescription<?> desc,
      ImageSingleBand input,
      ImageSingleBand expected,
      ImageSingleBand found) {
    int w = expected.width;
    int h = expected.height;

    int lowerBorder = UtilWavelet.borderForwardLower(desc.getInverse().getInnerCoefficients());
    int upperBorder =
        input.height
            - UtilWavelet.borderForwardUpper(
                desc.getInverse().getInnerCoefficients(), input.height);

    equalsTranVertical(
        expected.subimage(0, 0, w, h / 2),
        found.subimage(0, 0, w, h / 2),
        lowerBorder / 2,
        upperBorder / 2,
        "top");
    equalsTranVertical(
        expected.subimage(0, h / 2, w, h),
        found.subimage(0, h / 2, w, h),
        lowerBorder / 2,
        upperBorder / 2,
        "bottom");
  }
Ejemplo n.º 5
0
  /** Checks to see if only the image borders are equal to each other within tolerance */
  public static void assertEqualsBorder(
      ImageSingleBand imgA, ImageSingleBand imgB, double tol, int borderX, int borderY) {
    if (imgA.getWidth() != imgB.getWidth()) throw new RuntimeException("Widths are not equals");

    if (imgA.getHeight() != imgB.getHeight()) throw new RuntimeException("Heights are not equals");

    GImageSingleBand a = FactoryGImageSingleBand.wrap(imgA);
    GImageSingleBand b = FactoryGImageSingleBand.wrap(imgB);

    for (int y = 0; y < imgA.getHeight(); y++) {
      for (int x = 0; x < borderX; x++) {
        compareValues(tol, a, b, x, y);
      }
      for (int x = imgA.getWidth() - borderX; x < imgA.getWidth(); x++) {
        compareValues(tol, a, b, x, y);
      }
    }

    for (int x = borderX; x < imgA.getWidth() - borderX; x++) {
      for (int y = 0; y < borderY; y++) {
        compareValues(tol, a, b, x, y);
      }
      for (int y = imgA.getHeight() - borderY; y < imgA.getHeight(); y++) {
        compareValues(tol, a, b, x, y);
      }
    }
  }
Ejemplo n.º 6
0
  public static BufferedImage standard(ImageSingleBand<?> src, BufferedImage dst) {
    if (src.getDataType().isInteger()) {
      ImageInteger srcInt = (ImageInteger) src;

      if (src.getDataType().isSigned()) {
        double max = GImageStatistics.maxAbs(srcInt);
        return colorizeSign(srcInt, dst, (int) max);
      } else {
        if (src.getDataType().getNumBits() == 8) {
          dst = ConvertBufferedImage.convertTo((ImageUInt8) src, dst);
        } else {
          double max = GImageStatistics.maxAbs(srcInt);
          dst = grayUnsigned(srcInt, dst, (int) max);
        }
      }
    } else if (ImageFloat32.class.isAssignableFrom(src.getClass())) {
      ImageFloat32 img = (ImageFloat32) src;
      float max = ImageStatistics.maxAbs(img);

      boolean hasNegative = false;
      for (int i = 0; i < img.getHeight(); i++) {
        for (int j = 0; j < img.getWidth(); j++) {
          if (img.get(j, i) < 0) {
            hasNegative = true;
            break;
          }
        }
      }

      if (hasNegative) return colorizeSign(img, dst, (int) max);
      else return grayMagnitude((ImageFloat32) src, dst, max);
    }

    return dst;
  }
Ejemplo n.º 7
0
 public static void set(ImageSingleBand img, int x, int y, double value) {
   if (ImageInteger.class.isAssignableFrom(img.getClass())) {
     ((ImageInteger) img).set(x, y, (int) value);
   } else if (img instanceof ImageFloat32) {
     ((ImageFloat32) img).set(x, y, (float) value);
   } else if (img instanceof ImageFloat64) {
     ((ImageFloat64) img).set(x, y, value);
   } else {
     throw new IllegalArgumentException(
         "Unknown or incompatible image type: " + img.getClass().getSimpleName());
   }
 }
Ejemplo n.º 8
0
  public static void printDiff(ImageSingleBand imgA, ImageSingleBand imgB) {

    GImageSingleBand a = FactoryGImageSingleBand.wrap(imgA);
    GImageSingleBand b = FactoryGImageSingleBand.wrap(imgB);

    System.out.println("------- Difference -----------");
    for (int y = 0; y < imgA.getHeight(); y++) {
      for (int x = 0; x < imgA.getWidth(); x++) {
        double diff = Math.abs(a.get(x, y).doubleValue() - b.get(x, y).doubleValue());
        System.out.printf("%2d ", (int) diff);
      }
      System.out.println();
    }
  }
Ejemplo n.º 9
0
 public static Kernel2D convertToKernel(ImageSingleBand image) {
   if (image.getDataType().isInteger()) {
     return KernelMath.convertToKernel((ImageInteger) image);
   } else {
     return KernelMath.convertToKernel((ImageFloat32) image);
   }
 }
Ejemplo n.º 10
0
  /**
   * Converts an image from one type to another type.
   *
   * @param src Input image. Not modified.
   * @param dst Converted output image. Modified.
   * @return Converted image.
   */
  @SuppressWarnings({"unchecked"})
  public static void convert(ImageSingleBand<?> src, ImageSingleBand<?> dst) {
    if (src.getClass() == dst.getClass()) {
      ((ImageSingleBand) dst).setTo(src);
      return;
    }

    Method m =
        BoofTesting.findMethod(ImplConvertImage.class, "convert", src.getClass(), dst.getClass());
    try {
      m.invoke(null, src, dst);
    } catch (IllegalAccessException e) {
      throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
      throw new RuntimeException(e);
    }
  }
Ejemplo n.º 11
0
  /**
   * Renders a gray scale image using color values from cold to hot.
   *
   * @param disparity Input disparity image
   * @param dst Where the image is rendered into. If null a new BufferedImage will be created and
   *     return.
   * @param minDisparity Minimum disparity that can be computed
   * @param maxDisparity Maximum disparity that can be computed
   * @param invalidColor RGB value for invalid pixels. Try 0xFF << 8 for green
   * @return Rendered image.
   */
  public static BufferedImage disparity(
      ImageSingleBand disparity,
      BufferedImage dst,
      int minDisparity,
      int maxDisparity,
      int invalidColor) {
    if (dst == null)
      dst =
          new BufferedImage(
              disparity.getWidth(), disparity.getHeight(), BufferedImage.TYPE_INT_RGB);

    if (disparity.getDataType().isInteger()) {
      return disparity((ImageInteger) disparity, dst, minDisparity, maxDisparity, invalidColor);
    } else if (disparity instanceof ImageFloat32) {
      return disparity((ImageFloat32) disparity, dst, minDisparity, maxDisparity, invalidColor);
    } else {
      throw new RuntimeException("Add support");
    }
  }
Ejemplo n.º 12
0
  /**
   * Renders a gray scale image of the input image's intensity.<br>
   * <br>
   * dst(i,j) = 255*abs(src(i,j))/normalize
   *
   * @param src Input single band image.
   * @param dst Where the image is rendered into. If null a new BufferedImage will be created and
   *     return.
   * @param normalize Used to normalize the input image. If < 0 then this value is automatically
   *     computed.
   * @return Rendered image.
   */
  public static BufferedImage grayMagnitude(
      ImageSingleBand src, BufferedImage dst, double normalize) {
    if (normalize < 0) normalize = GImageStatistics.maxAbs(src);

    dst = checkInputs(src, dst);

    if (src.getDataType().isInteger()) {
      return grayMagnitude((ImageInteger) src, dst, (int) normalize);
    } else {
      return grayMagnitude((ImageFloat32) src, dst, (float) normalize);
    }
  }
Ejemplo n.º 13
0
  /**
   * Renders a gray scale image using color values from cold to hot.
   *
   * @param src Input single band image.
   * @param dst Where the image is rendered into. If null a new BufferedImage will be created and
   *     return.
   * @param normalize Used to normalize the input image.
   * @return Rendered image.
   */
  public static BufferedImage grayMagnitudeTemp(
      ImageSingleBand src, BufferedImage dst, double normalize) {
    if (normalize < 0) normalize = GImageStatistics.maxAbs(src);

    dst = checkInputs(src, dst);

    if (src.getDataType().isInteger()) {
      return grayMagnitudeTemp((ImageInteger) src, dst, (int) normalize);
    } else {
      throw new RuntimeException("Add support");
    }
  }
  public static void applyInnerMethod(
      String functionName,
      WaveletDescription<?> desc,
      ImageSingleBand input,
      ImageSingleBand output) {

    Method m;
    Object args[];
    if (functionName.contains("Inverse")) {
      WlCoef coef = desc.getInverse().getInnerCoefficients();
      m =
          BoofTesting.findMethod(
              ImplWaveletTransformInner.class,
              functionName,
              coef.getClass(),
              input.getClass(),
              output.getClass());
      args = new Object[] {coef, input, output};
    } else {
      WlCoef coef = desc.getForward();
      m =
          BoofTesting.findMethod(
              ImplWaveletTransformInner.class,
              functionName,
              coef.getClass(),
              input.getClass(),
              output.getClass());
      args = new Object[] {coef, input, output};
    }

    try {
      m.invoke(null, args);
    } catch (InvocationTargetException e) {
      throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
      throw new RuntimeException(e);
    }
  }
Ejemplo n.º 15
0
 public static double get(ImageSingleBand img, int x, int y) {
   if (img instanceof ImageInt8) {
     return ((ImageInt8) img).get(x, y);
   } else if (img instanceof ImageInt16) {
     return ((ImageInt16) img).get(x, y);
   } else if (img instanceof ImageSInt32) {
     return ((ImageSInt32) img).get(x, y);
   } else if (img instanceof ImageFloat32) {
     return ((ImageFloat32) img).get(x, y);
   } else if (img instanceof ImageFloat64) {
     return ((ImageFloat64) img).get(x, y);
   } else if (img instanceof ImageSInt64) {
     return ((ImageSInt64) img).get(x, y);
   } else {
     throw new IllegalArgumentException(
         "Unknown or incompatible image type: " + img.getClass().getSimpleName());
   }
 }
Ejemplo n.º 16
0
  /**
   * Renders a colored image where the color indicates the sign and intensity its magnitude. The
   * input is divided by normalize to render it in the appropriate scale.
   *
   * @param src Input single band image.
   * @param dst Where the image is rendered into. If null a new BufferedImage will be created and
   *     return.
   * @param normalize Used to normalize the input image. If <= 0 then the max value will be used
   * @return Rendered image.
   */
  public static BufferedImage colorizeSign(
      ImageSingleBand src, BufferedImage dst, double normalize) {
    dst = checkInputs(src, dst);

    if (normalize <= 0) {
      normalize = GImageStatistics.maxAbs(src);
    }

    if (normalize == 0) {
      // sets the output to black
      ConvertBufferedImage.convertTo(src, dst, true);
      return dst;
    }

    if (src.getClass().isAssignableFrom(ImageFloat32.class)) {
      return colorizeSign((ImageFloat32) src, dst, (float) normalize);
    } else {
      return colorizeSign((ImageInteger) src, dst, (int) normalize);
    }
  }
Ejemplo n.º 17
0
 @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);
 }