Ejemplo n.º 1
0
  /** Checks to see if the two ways of specifying interpolation work */
  @Test
  public void scale_InterpTypeStyle() {
    ImageFloat32 input = new ImageFloat32(width, height);
    ImageFloat32 output = new ImageFloat32(width, height);

    GImageMiscOps.fillUniform(input, rand, 0, 100);

    DistortImageOps.scale(input, output, TypeInterpolate.BILINEAR);

    InterpolatePixel<ImageFloat32> interp = FactoryInterpolation.bilinearPixel(input);
    interp.setImage(input);

    float scaleX = (float) input.width / (float) output.width;
    float scaleY = (float) input.height / (float) output.height;

    if (input.getTypeInfo().isInteger()) {
      for (int i = 0; i < output.height; i++) {
        for (int j = 0; j < output.width; j++) {
          float val = interp.get(j * scaleX, i * scaleY);
          assertEquals((int) val, output.get(j, i), 1e-4);
        }
      }
    } else {
      for (int i = 0; i < output.height; i++) {
        for (int j = 0; j < output.width; j++) {
          float val = interp.get(j * scaleX, i * scaleY);
          assertEquals(val, output.get(j, i), 1e-4);
        }
      }
    }
  }
Ejemplo n.º 2
0
  @Test
  public void scaleSanityCheck() {
    ImageFloat32 input = new ImageFloat32(width, height);
    ImageFloat32 output = new ImageFloat32(width / 2, height / 2);

    GImageMiscOps.fillUniform(input, rand, 0, 100);

    DistortImageOps.scale(input, output, TypeInterpolate.BILINEAR);

    double error = 0;
    for (int y = 0; y < output.height; y++) {
      for (int x = 0; x < output.width; x++) {
        double e = input.get(x * 2, y * 2) - output.get(x, y);
        error += Math.abs(e);
      }
    }
    assertTrue(error / (output.width * output.height) < 0.1);
  }