/** 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); } } } }
public void get(T img) { InterpolatePixel<T> interp = wrap(img, 0, 100); assertEquals(compute(img, 10, 10), interp.get(10, 10), 1e-5f); assertEquals(compute(img, 10.1f, 10), interp.get(10.1f, 10), 1e-5f); assertEquals(compute(img, 10, 10.6f), interp.get(10, 10.6f), 1e-5f); assertEquals(compute(img, 10.8f, 10.6f), interp.get(10.8f, 10.6f), 1e-5f); }
/** Sees if get throws an exception if it is out of bounds */ public void get_outside() { T img = createImage(width, height); InterpolatePixel<T> interp = wrap(img, 0, 100); try { interp.get(500, 10); if (exceptionOutside) fail("Didn't throw an exception when accessing an outside pixel"); } catch (IllegalArgumentException e) { } }
/** * Interpolates the whole image and sees if the values returned are within the specified bounds */ @Test public void checkPixelValueBoundsHonored() { T img = createImage(20, 30); GImageMiscOps.fillUniform(img, rand, 0, 100); InterpolatePixel<T> interp = wrap(img, 0, 100); for (int y = 0; y < img.height; y++) { for (int x = 0; x < img.width; x++) { float v = interp.get(x, y); assertTrue(v >= 0 && v <= 100); } } }
/** * Scans through the whole image and for each pixel which is "safe" it compares the safe value to * the unsafe value. */ @Test public void isInSafeBounds() { T img = createImage(width, height); GImageMiscOps.fillUniform(img, rand, 0, 100); InterpolatePixel<T> interp = wrap(img, 0, 100); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (interp.isInSafeBounds(x, y)) { float a = interp.get(x, y); float b = interp.get_unsafe(x, y); assertEquals(a, b, 1e-4); } } } }
public void get_unsafe(T img) { InterpolatePixel<T> interp = wrap(img, 0, 100); assertEquals(interp.get(10, 10), interp.get_unsafe(10, 10), 1e-6); assertEquals(interp.get(10.1f, 10), interp.get_unsafe(10.1f, 10), 1e-6); assertEquals(interp.get(10, 10.6f), interp.get_unsafe(10, 10.6f), 1e-6); assertEquals(interp.get(10.8f, 10.6f), interp.get_unsafe(10.8f, 10.6f), 1e-6); }
/** Try the same get at a few border points and see if anything blows up */ @Test public void checkSafeGetAlongBorder() { T img = createImage(width, height); GImageMiscOps.fillUniform(img, rand, 0, 100); InterpolatePixel<T> interp = wrap(img, 0, 100); // will it blow up? interp.get(0, 0); interp.get(width / 2, 0); interp.get(0, height / 2); interp.get(width - 1, height - 1); interp.get(width / 2, height - 1); interp.get(width - 1, height / 2); }
protected void compare(InterpolatePixel<T> interp, T img, float x, float y) { assertEquals(compute(img, x, y), interp.get(x, y), 1e-5f); }
@Test public void getImage() { T img = createImage(width, height); InterpolatePixel<T> interp = wrap(img, 0, 100); assertTrue(img == interp.getImage()); }