From e8f456a7e2684f3574e13a6831df4effab1fbe23 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 27 Jan 2015 21:45:14 +0000 Subject: [PATCH] more tests --- ChangeLog | 1 + test/test_create.py | 173 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0bd1b986..c1d6e471 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,7 @@ - try to handle tiffs with old-style 8-bit colormaps - rename vipsthumbnail -o as -f, -o stays as a hidden flag - fix some small leaks +- faster openslide load, thanks Benjamin 24/12/14 started 7.42.1 - add gobject-2.0 to Requires: in vips and vips-cpp .pc files diff --git a/test/test_create.py b/test/test_create.py index 392756d9..b4022ab1 100755 --- a/test/test_create.py +++ b/test/test_create.py @@ -139,8 +139,181 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.bands, 1) self.assertEqual(im.format, Vips.BandFormat.FLOAT) + im = Vips.Image.gaussnoise(100, 90, sigma = 10, mean = 100) + self.assertEqual(im.width, 100) + self.assertEqual(im.height, 90) + self.assertEqual(im.bands, 1) + self.assertEqual(im.format, Vips.BandFormat.FLOAT) + sigma = im.deviate() + mean = im.avg() + self.assertAlmostEqual(sigma, 10, places = 0) + self.assertAlmostEqual(mean, 100, places = 0) + + def test_grey(self): + im = Vips.Image.grey(100, 90) + self.assertEqual(im.width, 100) + self.assertEqual(im.height, 90) + self.assertEqual(im.bands, 1) + self.assertEqual(im.format, Vips.BandFormat.FLOAT) + + p = im.getpoint(0, 0) + self.assertEqual(p[0], 0.0) + p = im.getpoint(99, 0) + self.assertEqual(p[0], 1.0) + p = im.getpoint(0, 89) + self.assertEqual(p[0], 0.0) + p = im.getpoint(99, 89) + self.assertEqual(p[0], 1.0) + + im = Vips.Image.grey(100, 90, uchar = True) + self.assertEqual(im.width, 100) + self.assertEqual(im.height, 90) + self.assertEqual(im.bands, 1) + self.assertEqual(im.format, Vips.BandFormat.UCHAR) + + p = im.getpoint(0, 0) + self.assertEqual(p[0], 0) + p = im.getpoint(99, 0) + self.assertEqual(p[0], 255) + p = im.getpoint(0, 89) + self.assertEqual(p[0], 0) + p = im.getpoint(99, 89) + self.assertEqual(p[0], 255) + + def test_identity(self): + im = Vips.Image.identity() + self.assertEqual(im.width, 256) + self.assertEqual(im.height, 1) + self.assertEqual(im.bands, 1) + self.assertEqual(im.format, Vips.BandFormat.UCHAR) + + p = im.getpoint(0, 0) + self.assertEqual(p[0], 0.0) + p = im.getpoint(255, 0) + self.assertEqual(p[0], 255.0) + p = im.getpoint(128, 0) + self.assertEqual(p[0], 128.0) + + im = Vips.Image.identity(ushort = True) + self.assertEqual(im.width, 65536) + self.assertEqual(im.height, 1) + self.assertEqual(im.bands, 1) + self.assertEqual(im.format, Vips.BandFormat.USHORT) + + p = im.getpoint(0, 0) + self.assertEqual(p[0], 0) + p = im.getpoint(99, 0) + self.assertEqual(p[0], 99) + p = im.getpoint(65535, 0) + self.assertEqual(p[0], 65535) + + def test_invertlut(self): + lut = Vips.Image.new_from_array([[0.1, 0.2, 0.3, 0.1], + [0.2, 0.4, 0.4, 0.2], + [0.7, 0.5, 0.6, 0.3]]) + im = lut.invertlut() + self.assertEqual(im.width, 256) + self.assertEqual(im.height, 1) + self.assertEqual(im.bands, 3) + self.assertEqual(im.format, Vips.BandFormat.DOUBLE) + + p = im.getpoint(0, 0) + self.assertAlmostEqualObjects(p, [0, 0, 0]) + p = im.getpoint(255, 0) + self.assertAlmostEqualObjects(p, [1, 1, 1]) + p = im.getpoint(0.2 * 255, 0) + self.assertAlmostEqual(p[0], 0.1, places = 2) + p = im.getpoint(0.3 * 255, 0) + self.assertAlmostEqual(p[1], 0.1, places = 2) + p = im.getpoint(0.1 * 255, 0) + self.assertAlmostEqual(p[2], 0.1, places = 2) + + def test_logmat(self): + im = Vips.Image.logmat(1, 0.1) + self.assertEqual(im.width, 7) + self.assertEqual(im.height, 7) + self.assertEqual(im.bands, 1) + self.assertEqual(im.format, Vips.BandFormat.DOUBLE) + self.assertEqual(im.max(), 20) + total = im.avg() * im.width * im.height + scale = im.get("scale") + self.assertEqual(total, scale) + p = im.getpoint(im.width / 2, im.height / 2) + self.assertEqual(p[0], 20.0) + + im = Vips.Image.logmat(1, 0.1, + separable = True, precision = "float") + self.assertEqual(im.width, 7) + self.assertEqual(im.height, 1) + self.assertEqual(im.bands, 1) + self.assertEqual(im.format, Vips.BandFormat.DOUBLE) + self.assertEqual(im.max(), 1.0) + total = im.avg() * im.width * im.height + scale = im.get("scale") + self.assertEqual(total, scale) + p = im.getpoint(im.width / 2, im.height / 2) + self.assertEqual(p[0], 1.0) + + def test_mask_butterworth_band(self): + im = Vips.Image.mask_butterworth_band(128, 128, 2, 0.5, 0.5, 0.7, 0.1) + self.assertEqual(im.width, 128) + self.assertEqual(im.height, 128) + self.assertEqual(im.bands, 1) + self.assertEqual(im.format, Vips.BandFormat.FLOAT) + self.assertAlmostEqual(im.max(), 1, places = 2) + p = im.getpoint(32, 32) + self.assertEqual(p[0], 1.0) + + im = Vips.Image.mask_butterworth_band(128, 128, 2, 0.5, 0.5, 0.7, 0.1, + uchar = True, optical = True) + self.assertEqual(im.width, 128) + self.assertEqual(im.height, 128) + self.assertEqual(im.bands, 1) + self.assertEqual(im.format, Vips.BandFormat.UCHAR) + self.assertEqual(im.max(), 255) + p = im.getpoint(32, 32) + self.assertEqual(p[0], 255.0) + p = im.getpoint(64, 64) + self.assertEqual(p[0], 255.0) + + im = Vips.Image.mask_butterworth_band(128, 128, 2, 0.5, 0.5, 0.7, 0.1, + uchar = True, optical = True, + nodc = True) + self.assertEqual(im.width, 128) + self.assertEqual(im.height, 128) + self.assertEqual(im.bands, 1) + self.assertEqual(im.format, Vips.BandFormat.UCHAR) + self.assertEqual(im.max(), 255) + p = im.getpoint(32, 32) + self.assertEqual(p[0], 255.0) + p = im.getpoint(64, 64) + self.assertNotEqual(p[0], 255) + + def test_mask_butterworth(self): + im = Vips.Image.mask_butterworth(128, 128, 2, 0.7, 0.1, + nodc = True) + self.assertEqual(im.width, 128) + self.assertEqual(im.height, 128) + self.assertEqual(im.bands, 1) + self.assertEqual(im.format, Vips.BandFormat.FLOAT) + self.assertAlmostEqual(im.min(), 0, places = 2) + p = im.getpoint(0, 0) + self.assertEqual(p[0], 0.0) + v, x, y = im.maxpos() + self.assertEqual(x, 64) + self.assertEqual(y, 64) + + im = Vips.Image.mask_butterworth(128, 128, 2, 0.7, 0.1, + optical = True, uchar = True) + self.assertEqual(im.width, 128) + self.assertEqual(im.height, 128) + self.assertEqual(im.bands, 1) + self.assertEqual(im.format, Vips.BandFormat.UCHAR) + self.assertAlmostEqual(im.min(), 0, places = 2) + p = im.getpoint(64, 64) + self.assertEqual(p[0], 255) if __name__ == '__main__':