/** See how well it processes an image which is not an GrayS32 */ @Test public void checkOtherType() { GrayS32 orig = new GrayS32(width, height); GImageMiscOps.fillUniform(orig, rand, 0, 20); GrayU8 orig8 = ConvertImage.convert(orig, (GrayU8) null); int N = 3; ImageDimension dimen = UtilWavelet.transformDimension(orig, N); GrayS32 found = new GrayS32(dimen.width, dimen.height); GrayS32 expected = new GrayS32(dimen.width, dimen.height); WaveletDescription<WlCoef_I32> desc = FactoryWaveletDaub.biorthogonal_I32(5, BorderType.REFLECT); GrayS32 storage = new GrayS32(dimen.width, dimen.height); WaveletTransformOps.transformN(desc, orig.clone(), expected, storage, N); WaveletTransformInt<GrayU8> alg = new WaveletTransformInt<>(desc, N, 0, 255, GrayU8.class); alg.transform(orig8, found); // see if the two techniques produced the same results BoofTesting.assertEquals(expected, found, 0); // see if it can convert it back GrayU8 reconstructed = new GrayU8(width, height); alg.invert(found, reconstructed); BoofTesting.assertEquals(orig8, reconstructed, 0); // make sure the input has not been modified BoofTesting.assertEquals(expected, found, 0); }
@Test public void compareToWaveletTransformOps() { GrayS32 orig = new GrayS32(width, height); GImageMiscOps.fillUniform(orig, rand, 0, 20); GrayS32 origCopy = orig.clone(); int N = 3; ImageDimension dimen = UtilWavelet.transformDimension(orig, N); GrayS32 found = new GrayS32(dimen.width, dimen.height); GrayS32 expected = new GrayS32(dimen.width, dimen.height); WaveletDescription<WlCoef_I32> desc = FactoryWaveletDaub.biorthogonal_I32(5, BorderType.REFLECT); GrayS32 storage = new GrayS32(dimen.width, dimen.height); WaveletTransformOps.transformN(desc, orig.clone(), expected, storage, N); WaveletTransformInt<GrayS32> alg = new WaveletTransformInt<>(desc, N, 0, 255, GrayS32.class); alg.transform(orig, found); // make sure the original input was not modified like it is in WaveletTransformOps BoofTesting.assertEquals(origCopy, orig, 0); // see if the two techniques produced the same results BoofTesting.assertEquals(expected, found, 0); // test inverse transform GrayS32 reconstructed = new GrayS32(width, height); alg.invert(found, reconstructed); BoofTesting.assertEquals(orig, reconstructed, 0); // make sure the input has not been modified BoofTesting.assertEquals(expected, found, 0); }
public static <T extends ImageSingleBand> T createSingleBand( Class<T> type, int width, int height) { type = BoofTesting.convertGenericToSpecificType(type); if (type == ImageUInt8.class) { return (T) new ImageUInt8(width, height); } else if (type == ImageSInt8.class) { return (T) new ImageSInt8(width, height); } else if (type == ImageSInt16.class) { return (T) new ImageSInt16(width, height); } else if (type == ImageUInt16.class) { return (T) new ImageUInt16(width, height); } else if (type == ImageSInt32.class) { return (T) new ImageSInt32(width, height); } else if (type == ImageSInt64.class) { return (T) new ImageSInt64(width, height); } else if (type == ImageFloat32.class) { return (T) new ImageFloat32(width, height); } else if (type == ImageFloat64.class) { return (T) new ImageFloat64(width, height); } else if (type == ImageInteger.class) { // ImageInteger is a generic type, so just create something return (T) new ImageSInt32(width, height); } throw new RuntimeException("Unknown type: " + type.getSimpleName()); }
/** See if accessing the image edge causes it to blow up. */ @Test public void get_edges() { T img = createImage(width, height); GImageMiscOps.fillUniform(img, rand, 0, 100); BoofTesting.checkSubImage(this, "get_edges", false, img); }
/** The XY and YX second derivatives should be indential */ private void testSecondDerivative(Method m1, Method m2) { Class params[] = m1.getParameterTypes(); ImageGray input = GeneralizedImageOps.createSingleBand(params[0], width, height); ImageGray derivX = GeneralizedImageOps.createSingleBand(params[1], width, height); ImageGray derivY = GeneralizedImageOps.createSingleBand(params[2], width, height); ImageGray derivXX = GeneralizedImageOps.createSingleBand(params[1], width, height); ImageGray derivYY = GeneralizedImageOps.createSingleBand(params[2], width, height); ImageGray derivXY = GeneralizedImageOps.createSingleBand(params[1], width, height); ImageGray derivYX = GeneralizedImageOps.createSingleBand(params[1], width, height); GImageMiscOps.fillUniform(input, rand, 0, 40); Object border; if (params[3] == ImageBorder_F32.class) { border = new ImageBorder1D_F32(BorderIndex1D_Wrap.class); } else { border = new ImageBorder1D_S32(BorderIndex1D_Wrap.class); } try { m1.invoke(null, input, derivX, derivY, border); m2.invoke(null, derivX, derivXX, derivXY, border); m2.invoke(null, derivY, derivYX, derivYY, border); } catch (IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } // BoofTesting.printDiff(derivXY,derivYX); BoofTesting.assertEquals(derivXY, derivYX, 1e-3f); }
/** * Creates a random image and looks for corners in it. Sees if the naive and fast algorithm * produce exactly the same results. */ @Test public void compareToNaive() { GrayU8 img = new GrayU8(width, height); ImageMiscOps.fillUniform(img, new Random(0xfeed), 0, 100); GrayS16 derivX = new GrayS16(img.getWidth(), img.getHeight()); GrayS16 derivY = new GrayS16(img.getWidth(), img.getHeight()); GradientSobel.process(img, derivX, derivY, new ImageBorder1D_S32(BorderIndex1D_Extend.class)); BoofTesting.checkSubImage(this, "compareToNaive", true, derivX, derivY); }
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); } }
public void compareToNaive(GrayS16 derivX, GrayS16 derivY) { GrayF32 expected = new GrayF32(derivX.width, derivX.height); GrayF32 found = new GrayF32(derivX.width, derivX.height); ImplSsdCornerNaive naive = new ImplSsdCornerNaive(width, height, 3, true); naive.process(derivX, derivY, expected); ImplShiTomasiCornerWeighted_S16 fast = new ImplShiTomasiCornerWeighted_S16(3); fast.process(derivX, derivY, found); // how the weighted is applied is different between these two verisons, which is why the error // tolerance is so high BoofTesting.assertEqualsInner(expected, found, 0.5, 3, 3, true); }
/** * 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); } }
private void compareToNaive( Image left, Image right, int minDisparity, int maxDisparity, int radiusX, int radiusY) { int w = left.width; int h = left.height; DisparityScoreSadRect<Image, Disparity> alg = createAlg(minDisparity, maxDisparity, radiusX, radiusY, compDisp); StereoDisparityWtoNaive<Image> naive = new StereoDisparityWtoNaive<Image>(minDisparity, maxDisparity, radiusX, radiusY); Disparity found = GeneralizedImageOps.createSingleBand(disparityType, w, h); ImageFloat32 expected = new ImageFloat32(w, h); alg.process(left, right, found); naive.process(left, right, expected); BoofTesting.assertEquals(found, expected, 1); }
/** Process two images, one is a sub-image of the first. See if it produces the same results */ @Test public void checkSubImage() { SiftImageScaleSpace ss1 = new SiftImageScaleSpace(1.6f, 5, 4, false); SiftImageScaleSpace ss2 = new SiftImageScaleSpace(1.6f, 5, 4, false); ImageFloat32 input = new ImageFloat32(60, 70); GImageMiscOps.fillUniform(input, rand, 0, 100); ImageFloat32 sub = BoofTesting.createSubImageOf(input); ss1.constructPyramid(input); ss2.constructPyramid(sub); for (int index = 0; index < ss1.scale.length; index++) { ImageFloat32 s1 = ss1.scale[index]; ImageFloat32 s2 = ss2.scale[index]; float sum1 = ImageStatistics.sum(s1); float sum2 = ImageStatistics.sum(s2); assertTrue(sum1 != 0); assertEquals(sum1, sum2, 1e-6); } }
@Test public void border() { BoofTesting.checkSubImage(this, "checkBorder", false, img, 0, 0, 5, 7); BoofTesting.checkSubImage(this, "checkBorder", false, img, img.width - 1, img.height - 1, 5, 7); BoofTesting.checkSubImage(this, "checkBorder", false, img, 100, 200, 5, 7); }
@Test public void inner() { BoofTesting.checkSubImage(this, "checkInner", false, img, 4, 6, 7, 5); BoofTesting.checkSubImage(this, "checkInner", false, img, 7, 3, 4, 5); BoofTesting.checkSubImage(this, "checkInner", false, img, 4, 6, 2, 4); }