Example #1
0
 /**
  * If null the dst is declared, otherwise it checks to see if the 'dst' as the same shape as
  * 'src'.
  *
  * <p>The returned image will be 8-bit RGB
  */
 private static BufferedImage checkInputs(ImageBase src, BufferedImage dst) {
   if (dst != null) {
     if (dst.getWidth() != src.getWidth() || dst.getHeight() != src.getHeight()) {
       throw new IllegalArgumentException("image dimension are different");
     }
   } else {
     dst = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_RGB);
   }
   return dst;
 }
Example #2
0
 public static void checkEquals(
     BufferedImage imgA, ImageBase imgB, boolean boofcvBandOrder, double tol) {
   if (ImageUInt8.class == imgB.getClass()) {
     checkEquals(imgA, (ImageUInt8) imgB);
   } else if (ImageInt16.class.isAssignableFrom(imgB.getClass())) {
     checkEquals(imgA, (ImageInt16) imgB);
   } else if (ImageFloat32.class == imgB.getClass()) {
     checkEquals(imgA, (ImageFloat32) imgB, (float) tol);
   } else if (InterleavedU8.class == imgB.getClass()) {
     checkEquals(imgA, (InterleavedU8) imgB);
   } else if (MultiSpectral.class == imgB.getClass()) {
     checkEquals(imgA, (MultiSpectral) imgB, boofcvBandOrder, (float) tol);
   } else {
     throw new IllegalArgumentException("Unknown");
   }
 }
Example #3
0
  // TODO make sure pixels outside are not modified of sub-matrix
  // todo have the submatrices be from different shaped inputs
  @SuppressWarnings({"unchecked"})
  public static void checkSubImage(
      Object testClass, String function, boolean checkEquals, Object... inputParam) {
    try {
      ImageBase[] larger = new ImageBase[inputParam.length];
      ImageBase[] subImg = new ImageBase[inputParam.length];
      Class<?> paramDesc[] = new Class<?>[inputParam.length];
      Object[] inputModified = new Object[inputParam.length];

      for (int i = 0; i < inputParam.length; i++) {
        if (ImageBase.class.isAssignableFrom(inputParam[i].getClass())) {
          ImageBase<?> img = (ImageBase<?>) inputParam[i];

          // copy the original image inside of a larger image
          larger[i] = img._createNew(img.getWidth() + 10, img.getHeight() + 12);
          // extract a sub-image and make it equivalent to the original image.
          subImg[i] = larger[i].subimage(5, 6, 5 + img.getWidth(), 6 + img.getHeight(), null);
          subImg[i].setTo(img);
        }

        // the first time it is called use the original inputs
        inputModified[i] = inputParam[i];
        paramDesc[i] = inputParam[i].getClass();
      }

      // first try it with the original image
      Method m = findMethod(testClass.getClass(), function, paramDesc);

      m.invoke(testClass, inputModified);

      // now try it with the sub-image
      for (int i = 0; i < inputModified.length; i++) {
        if (subImg[i] != null) inputModified[i] = subImg[i];
      }
      m.invoke(testClass, inputModified);

      // the result should be the identical
      if (checkEquals) {
        for (int i = 0; i < inputParam.length; i++) {
          if (subImg[i] == null) continue;
          assertEquals((ImageBase) inputModified[i], subImg[i], 0);
        }
      }

    } catch (InvocationTargetException e) {
      throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
      throw new RuntimeException(e);
    }
  }