diff --git a/TODO b/TODO index 99e8ccb5..702a0067 100644 --- a/TODO +++ b/TODO @@ -3,20 +3,6 @@ python people are not going to want to use the glib arg parser, for example -- need to add [] overload to Ruby bindings - -- overload (x, y) to be getpoint()? py/rb - - c++ has: - - std::vector operator()( int x, int y ) - { - return( this->getpoint( x, y ) ); - } - - - - diff --git a/doc/using-python.xml b/doc/using-python.xml index 620c1c70..34744409 100644 --- a/doc/using-python.xml +++ b/doc/using-python.xml @@ -349,7 +349,8 @@ result_image = ((image * [1, 2, 3]).abs() < 128) | 4 - The wrapper overloads [] to be band indexing. You can write: + The wrapper overloads [] to be vips_extract_band(). You + can write: result_image = image[2] @@ -367,6 +368,19 @@ result_image = [x.avg() for x in image] and so on. + + + The wrapper overloads () to be vips_getpoint(). You can + write: + + +r, g, b = image(10, 10) + + + to read out the value of the pixel at coordinates (10, 10) from an RGB + image. + + diff --git a/python/Vips.py b/python/Vips.py index 5ee8dc90..fdb7aa2f 100644 --- a/python/Vips.py +++ b/python/Vips.py @@ -783,6 +783,9 @@ class Image(Vips.Image): return self.extract_band(i, n = n) + def __call__(self, x, y): + return self.getpoint(x, y) + # the cast operators int(), long() and float() must return numeric types, # so we can't define them for images diff --git a/test/test_arithmetic.py b/test/test_arithmetic.py index 2265c688..53938105 100755 --- a/test/test_arithmetic.py +++ b/test/test_arithmetic.py @@ -66,10 +66,10 @@ class TestArithmetic(unittest.TestCase): # run a function on an image and on a single pixel, the results # should match def run_cmp(self, message, im, x, y, fn): - a = im.getpoint(x, y) + a = im(x, y) v1 = fn(a) im2 = fn(im) - v2 = im2.getpoint(x, y) + v2 = im2(x, y) self.assertAlmostEqualObjects(v1, v2, msg = message) # run a function on (image, constant), and on (constant, image). @@ -90,11 +90,11 @@ class TestArithmetic(unittest.TestCase): # run a function on a pair of images and on a pair of pixels, the results # should match def run_cmp2(self, message, left, right, x, y, fn): - a = left.getpoint(x, y) - b = right.getpoint(x, y) + a = left(x, y) + b = right(x, y) v1 = fn(a, b) after = fn(left, right) - v2 = after.getpoint(x, y) + v2 = after(x, y) self.assertAlmostEqualObjects(v1, v2, msg = message) # run a function on a pair of images @@ -392,22 +392,22 @@ class TestArithmetic(unittest.TestCase): for fmt in all_formats: hist = test.cast(fmt).hist_find() - self.assertAlmostEqualObjects(hist.getpoint(0,0), [5000]) - self.assertAlmostEqualObjects(hist.getpoint(10,0), [5000]) - self.assertAlmostEqualObjects(hist.getpoint(5,0), [0]) + self.assertAlmostEqualObjects(hist(0,0), [5000]) + self.assertAlmostEqualObjects(hist(10,0), [5000]) + self.assertAlmostEqualObjects(hist(5,0), [0]) test = test * [1, 2, 3] for fmt in all_formats: hist = test.cast(fmt).hist_find(band = 0) - self.assertAlmostEqualObjects(hist.getpoint(0,0), [5000]) - self.assertAlmostEqualObjects(hist.getpoint(10,0), [5000]) - self.assertAlmostEqualObjects(hist.getpoint(5,0), [0]) + self.assertAlmostEqualObjects(hist(0,0), [5000]) + self.assertAlmostEqualObjects(hist(10,0), [5000]) + self.assertAlmostEqualObjects(hist(5,0), [0]) hist = test.cast(fmt).hist_find(band = 1) - self.assertAlmostEqualObjects(hist.getpoint(0,0), [5000]) - self.assertAlmostEqualObjects(hist.getpoint(20,0), [5000]) - self.assertAlmostEqualObjects(hist.getpoint(5,0), [0]) + self.assertAlmostEqualObjects(hist(0,0), [5000]) + self.assertAlmostEqualObjects(hist(20,0), [5000]) + self.assertAlmostEqualObjects(hist(5,0), [0]) def test_histfind_indexed(self): im = Vips.Image.black(50, 100) @@ -420,8 +420,8 @@ class TestArithmetic(unittest.TestCase): b = index.cast(y) hist = a.hist_find_indexed(b) - self.assertAlmostEqualObjects(hist.getpoint(0,0), [0]) - self.assertAlmostEqualObjects(hist.getpoint(1,0), [50000]) + self.assertAlmostEqualObjects(hist(0,0), [0]) + self.assertAlmostEqualObjects(hist(1,0), [50000]) def test_histfind_ndim(self): im = Vips.Image.black(100, 100) + [1, 2, 3] @@ -429,12 +429,12 @@ class TestArithmetic(unittest.TestCase): for fmt in noncomplex_formats: hist = im.cast(fmt).hist_find_ndim() - self.assertAlmostEqualObjects(hist.getpoint(0,0)[0], 10000) - self.assertAlmostEqualObjects(hist.getpoint(5,5)[5], 0) + self.assertAlmostEqualObjects(hist(0,0)[0], 10000) + self.assertAlmostEqualObjects(hist(5,5)[5], 0) hist = im.cast(fmt).hist_find_ndim(bins = 1) - self.assertAlmostEqualObjects(hist.getpoint(0,0)[0], 10000) + self.assertAlmostEqualObjects(hist(0,0)[0], 10000) self.assertEqual(hist.width, 1) self.assertEqual(hist.height, 1) self.assertEqual(hist.bands, 1) @@ -447,7 +447,7 @@ class TestArithmetic(unittest.TestCase): hough = im.hough_circle(min_radius = 35, max_radius = 45) v, x, y = hough.maxpos() - vec = hough.getpoint(x, y) + vec = hough(x, y) r = vec.index(v) + 35 self.assertAlmostEqual(x, 50) @@ -634,8 +634,8 @@ class TestArithmetic(unittest.TestCase): for x in noncomplex_formats: a = test.cast(x) matrix = a.measure(2, 1) - [p1] = matrix.getpoint(0, 0) - [p2] = matrix.getpoint(0, 1) + [p1] = matrix(0, 0) + [p2] = matrix(0, 1) self.assertAlmostEqual(p1, 0) self.assertAlmostEqual(p2, 10) @@ -663,10 +663,10 @@ class TestArithmetic(unittest.TestCase): for fmt in noncomplex_formats: columns, rows = test.cast(fmt).project() - self.assertAlmostEqualObjects(columns.getpoint(10,0), [0]) - self.assertAlmostEqualObjects(columns.getpoint(70,0), [50 * 10]) + self.assertAlmostEqualObjects(columns(10,0), [0]) + self.assertAlmostEqualObjects(columns(70,0), [50 * 10]) - self.assertAlmostEqualObjects(rows.getpoint(0,10), [50 * 10]) + self.assertAlmostEqualObjects(rows(0,10), [50 * 10]) def test_stats(self): im = Vips.Image.black(50, 50) @@ -676,19 +676,19 @@ class TestArithmetic(unittest.TestCase): a = test.cast(x) matrix = a.stats() - self.assertAlmostEqualObjects(matrix.getpoint(0, 0), [a.min()]) - self.assertAlmostEqualObjects(matrix.getpoint(1, 0), [a.max()]) - self.assertAlmostEqualObjects(matrix.getpoint(2, 0), [50 * 50 * 10]) - self.assertAlmostEqualObjects(matrix.getpoint(3, 0), [50 * 50 * 100]) - self.assertAlmostEqualObjects(matrix.getpoint(4, 0), [a.avg()]) - self.assertAlmostEqualObjects(matrix.getpoint(5, 0), [a.deviate()]) + self.assertAlmostEqualObjects(matrix(0, 0), [a.min()]) + self.assertAlmostEqualObjects(matrix(1, 0), [a.max()]) + self.assertAlmostEqualObjects(matrix(2, 0), [50 * 50 * 10]) + self.assertAlmostEqualObjects(matrix(3, 0), [50 * 50 * 100]) + self.assertAlmostEqualObjects(matrix(4, 0), [a.avg()]) + self.assertAlmostEqualObjects(matrix(5, 0), [a.deviate()]) - self.assertAlmostEqualObjects(matrix.getpoint(0, 1), [a.min()]) - self.assertAlmostEqualObjects(matrix.getpoint(1, 1), [a.max()]) - self.assertAlmostEqualObjects(matrix.getpoint(2, 1), [50 * 50 * 10]) - self.assertAlmostEqualObjects(matrix.getpoint(3, 1), [50 * 50 * 100]) - self.assertAlmostEqualObjects(matrix.getpoint(4, 1), [a.avg()]) - self.assertAlmostEqualObjects(matrix.getpoint(5, 1), [a.deviate()]) + self.assertAlmostEqualObjects(matrix(0, 1), [a.min()]) + self.assertAlmostEqualObjects(matrix(1, 1), [a.max()]) + self.assertAlmostEqualObjects(matrix(2, 1), [50 * 50 * 10]) + self.assertAlmostEqualObjects(matrix(3, 1), [50 * 50 * 100]) + self.assertAlmostEqualObjects(matrix(4, 1), [a.avg()]) + self.assertAlmostEqualObjects(matrix(5, 1), [a.deviate()]) def test_sum(self): for fmt in all_formats: diff --git a/test/test_colour.py b/test/test_colour.py index ab2f8df1..941d81b9 100755 --- a/test/test_colour.py +++ b/test/test_colour.py @@ -79,20 +79,20 @@ class TestColour(unittest.TestCase): # run a function on an image and on a single pixel, the results # should match def run_cmp(self, message, im, x, y, fn): - a = im.getpoint(x, y) + a = im(x, y) v1 = fn(a) im2 = fn(im) - v2 = im2.getpoint(x, y) + v2 = im2(x, y) self.assertAlmostEqualObjects(v1, v2, msg = message) # run a function on a pair of images and on a pair of pixels, the results # should match def run_cmp2(self, message, left, right, x, y, fn): - a = left.getpoint(x, y) - b = right.getpoint(x, y) + a = left(x, y) + b = right(x, y) v1 = fn(a, b) after = fn(left, right) - v2 = after.getpoint(x, y) + v2 = after(x, y) self.assertAlmostEqualObjects(v1, v2, msg = message) # run a function on a pair of images @@ -126,7 +126,7 @@ class TestColour(unittest.TestCase): h = im.extract_band(i).max() self.assertAlmostEqual(l, h) - pixel = im.getpoint(10, 10) + pixel = im(10, 10) self.assertAlmostEqual(pixel[3], 42, places = 2) # alpha won't be equal for RGB16, but it should be preserved if we go @@ -134,8 +134,8 @@ class TestColour(unittest.TestCase): im = im.colourspace(Vips.Interpretation.RGB16) im = im.colourspace(Vips.Interpretation.LAB) - before = test.getpoint(10, 10) - after = im.getpoint(10, 10) + before = test(10, 10) + after = im(10, 10) self.assertAlmostEqualObjects(before, after, places = 1) # go between every pair of colour spaces @@ -145,15 +145,15 @@ class TestColour(unittest.TestCase): im2 = im.colourspace(end) im3 = im2.colourspace(Vips.Interpretation.LAB) - before = test.getpoint(10, 10) - after = im3.getpoint(10, 10) + before = test(10, 10) + after = im3(10, 10) self.assertAlmostEqualObjects(before, after, places = 1) # test Lab->XYZ on mid-grey # checked against http://www.brucelindbloom.com im = test.colourspace(Vips.Interpretation.XYZ) - after = im.getpoint(10, 10) + after = im(10, 10) self.assertAlmostEqualObjects(after, [17.5064, 18.4187, 20.0547, 42]) # grey->colour->grey should be equal @@ -163,8 +163,8 @@ class TestColour(unittest.TestCase): for col in colour_colourspaces + [mono_fmt]: im = im.colourspace(col) self.assertEqual(im.interpretation, col) - [before, alpha_before] = test_grey.getpoint(10, 10) - [after, alpha_after] = im.getpoint(10, 10) + [before, alpha_before] = test_grey(10, 10) + [after, alpha_after] = im(10, 10) self.assertLess(abs(alpha_after - alpha_before), 1) if mono_fmt == Vips.Interpretation.GREY16: # GREY16 can wind up rather different due to rounding @@ -184,7 +184,7 @@ class TestColour(unittest.TestCase): sample = sample.copy(interpretation = Vips.Interpretation.LAB) difference = reference.dE00(sample) - result, alpha = difference.getpoint(10, 10) + result, alpha = difference(10, 10) self.assertAlmostEqual(result, 30.238, places = 3) self.assertAlmostEqual(alpha, 42.0, places = 3) @@ -196,7 +196,7 @@ class TestColour(unittest.TestCase): sample = sample.copy(interpretation = Vips.Interpretation.LAB) difference = reference.dE76(sample) - result, alpha = difference.getpoint(10, 10) + result, alpha = difference(10, 10) self.assertAlmostEqual(result, 33.166, places = 3) self.assertAlmostEqual(alpha, 42.0, places = 3) @@ -210,7 +210,7 @@ class TestColour(unittest.TestCase): sample = sample.copy(interpretation = Vips.Interpretation.LAB) difference = reference.dECMC(sample) - result, alpha = difference.getpoint(10, 10) + result, alpha = difference(10, 10) self.assertLess(abs(result - 4.97), 0.5) self.assertAlmostEqual(alpha, 42.0, places = 3) diff --git a/test/test_conversion.py b/test/test_conversion.py index df4e03ad..f4b0c469 100755 --- a/test/test_conversion.py +++ b/test/test_conversion.py @@ -100,20 +100,20 @@ class TestConversion(unittest.TestCase): # run a function on an image and on a single pixel, the results # should match def run_cmp_unary(self, message, im, x, y, fn): - a = im.getpoint(x, y) + a = im(x, y) v1 = fn(a) im2 = fn(im) - v2 = im2.getpoint(x, y) + v2 = im2(x, y) self.assertAlmostEqualObjects(v1, v2, msg = message) # run a function on a pair of images and on a pair of pixels, the results # should match def run_cmp_binary(self, message, left, right, x, y, fn): - a = left.getpoint(x, y) - b = right.getpoint(x, y) + a = left(x, y) + b = right(x, y) v1 = fn(a, b) after = fn(left, right) - v2 = after.getpoint(x, y) + v2 = after(x, y) self.assertAlmostEqualObjects(v1, v2, msg = message) # run a function on a pair of images @@ -242,20 +242,20 @@ class TestConversion(unittest.TestCase): im = test.embed(20, 20, self.colour.width + 40, self.colour.height + 40) - pixel = im.getpoint(10, 10) + pixel = im(10, 10) self.assertAlmostEqualObjects(pixel, [0, 0, 0]) - pixel = im.getpoint(30, 30) + pixel = im(30, 30) self.assertAlmostEqualObjects(pixel, [2, 3, 4]) - pixel = im.getpoint(im.width - 10, im.height - 10) + pixel = im(im.width - 10, im.height - 10) self.assertAlmostEqualObjects(pixel, [0, 0, 0]) im = test.embed(20, 20, self.colour.width + 40, self.colour.height + 40, extend = Vips.Extend.COPY) - pixel = im.getpoint(10, 10) + pixel = im(10, 10) self.assertAlmostEqualObjects(pixel, [2, 3, 4]) - pixel = im.getpoint(im.width - 10, im.height - 10) + pixel = im(im.width - 10, im.height - 10) self.assertAlmostEqualObjects(pixel, [2, 3, 4]) im = test.embed(20, 20, @@ -263,20 +263,20 @@ class TestConversion(unittest.TestCase): self.colour.height + 40, extend = Vips.Extend.BACKGROUND, background = [7, 8, 9]) - pixel = im.getpoint(10, 10) + pixel = im(10, 10) self.assertAlmostEqualObjects(pixel, [7, 8, 9]) - pixel = im.getpoint(im.width - 10, im.height - 10) + pixel = im(im.width - 10, im.height - 10) self.assertAlmostEqualObjects(pixel, [7, 8, 9]) im = test.embed(20, 20, self.colour.width + 40, self.colour.height + 40, extend = Vips.Extend.WHITE) - pixel = im.getpoint(10, 10) + pixel = im(10, 10) # uses 255 in all bytes of ints, 255.0 for float pixel = [int(x) & 0xff for x in pixel] self.assertAlmostEqualObjects(pixel, [255, 255, 255]) - pixel = im.getpoint(im.width - 10, im.height - 10) + pixel = im(im.width - 10, im.height - 10) pixel = [int(x) & 0xff for x in pixel] self.assertAlmostEqualObjects(pixel, [255, 255, 255]) @@ -284,17 +284,17 @@ class TestConversion(unittest.TestCase): for fmt in all_formats: test = self.colour.cast(fmt) - pixel = test.getpoint(30, 30) + pixel = test(30, 30) self.assertAlmostEqualObjects(pixel, [2, 3, 4]) sub = test.extract_area(25, 25, 10, 10) - pixel = sub.getpoint(5, 5) + pixel = sub(5, 5) self.assertAlmostEqualObjects(pixel, [2, 3, 4]) sub = test.extract_band(1, n = 2) - pixel = sub.getpoint(30, 30) + pixel = sub(30, 30) self.assertAlmostEqualObjects(pixel, [3, 4]) def test_slice(self): @@ -326,12 +326,12 @@ class TestConversion(unittest.TestCase): for fmt in all_formats: test = self.colour.cast(fmt) - pixel = test.getpoint(30, 30) + pixel = test(30, 30) self.assertAlmostEqualObjects(pixel, [2, 3, 4]) sub = test.crop(25, 25, 10, 10) - pixel = sub.getpoint(5, 5) + pixel = sub(5, 5) self.assertAlmostEqualObjects(pixel, [2, 3, 4]) def test_falsecolour(self): @@ -344,7 +344,7 @@ class TestConversion(unittest.TestCase): self.assertEqual(im.height, test.height) self.assertEqual(im.bands, 3) - pixel = im.getpoint(30, 30) + pixel = im(30, 30) self.assertAlmostEqualObjects(pixel, [20, 0, 41]) def test_flatten(self): @@ -365,14 +365,14 @@ class TestConversion(unittest.TestCase): alpha = mx / 2.0 nalpha = mx - alpha test = self.colour.bandjoin(black + alpha).cast(fmt) - pixel = test.getpoint(30, 30) + pixel = test(30, 30) predict = [int(x) * alpha / mx for x in pixel[:-1]] im = test.flatten() self.assertEqual(im.bands, 3) - pixel = im.getpoint(30, 30) + pixel = im(30, 30) for x, y in zip(pixel, predict): # we use float arithetic for int and uint, so the rounding # differs ... don't require huge accuracy @@ -380,12 +380,12 @@ class TestConversion(unittest.TestCase): im = test.flatten(background = [100, 100, 100]) - pixel = test.getpoint(30, 30) + pixel = test(30, 30) predict = [int(x) * alpha / mx + (100 * nalpha) / mx for x in pixel[:-1]] self.assertEqual(im.bands, 3) - pixel = im.getpoint(30, 30) + pixel = im(30, 30) for x, y in zip(pixel, predict): self.assertLess(abs(x - y), 2) @@ -410,8 +410,8 @@ class TestConversion(unittest.TestCase): norm = mx ** exponent / mx result = test.gamma() - before = test.getpoint(30, 30) - after = result.getpoint(30, 30) + before = test(30, 30) + after = result(30, 30) predict = [x ** exponent / norm for x in before] for a, b in zip(after, predict): # ie. less than 1% error, rounding on 7-bit images means this is @@ -425,8 +425,8 @@ class TestConversion(unittest.TestCase): norm = mx ** exponent / mx result = test.gamma(exponent = 1.0 / 1.2) - before = test.getpoint(30, 30) - after = result.getpoint(30, 30) + before = test(30, 30) + after = result(30, 30) predict = [x ** exponent / norm for x in before] for a, b in zip(after, predict): # ie. less than 1% error, rounding on 7-bit images means this is @@ -444,12 +444,12 @@ class TestConversion(unittest.TestCase): self.assertEqual(result.width, self.colour.width * 3) self.assertEqual(result.height, self.colour.height * 4) - before = im.getpoint(10, 10) - after = result.getpoint(10 + test.width * 2, 10 + test.width * 2) + before = im(10, 10) + after = result(10 + test.width * 2, 10 + test.width * 2) self.assertAlmostEqualObjects(before, after) - before = im.getpoint(50, 50) - after = result.getpoint(50 + test.width * 2, 50 + test.width * 2) + before = im(50, 50) + after = result(50 + test.width * 2, 50 + test.width * 2) self.assertAlmostEqualObjects(before, after) def test_ifthenelse(self): @@ -464,12 +464,12 @@ class TestConversion(unittest.TestCase): self.assertEqual(r.height, self.colour.height) self.assertEqual(r.bands, self.colour.bands) - predict = e.getpoint(10, 10) - result = r.getpoint(10, 10) + predict = e(10, 10) + result = r(10, 10) self.assertAlmostEqualObjects(result, predict) - predict = t.getpoint(50, 50) - result = r.getpoint(50, 50) + predict = t(50, 50) + result = r(50, 50) self.assertAlmostEqualObjects(result, predict) test = self.colour > 3 @@ -483,20 +483,20 @@ class TestConversion(unittest.TestCase): self.assertEqual(r.height, self.colour.height) self.assertEqual(r.bands, self.colour.bands) - cp = test.getpoint(10, 10) - tp = t.getpoint(10, 10) * 3 - ep = e.getpoint(10, 10) * 3 + cp = test(10, 10) + tp = t(10, 10) * 3 + ep = e(10, 10) * 3 predict = [te if ce != 0 else ee for ce, te, ee in zip(cp, tp, ep)] - result = r.getpoint(10, 10) + result = r(10, 10) self.assertAlmostEqualObjects(result, predict) - cp = test.getpoint(50, 50) - tp = t.getpoint(50, 50) * 3 - ep = e.getpoint(50, 50) * 3 + cp = test(50, 50) + tp = t(50, 50) * 3 + ep = e(50, 50) * 3 predict = [te if ce != 0 else ee for ce, te, ee in zip(cp, tp, ep)] - result = r.getpoint(50, 50) + result = r(50, 50) self.assertAlmostEqualObjects(result, predict) test = self.colour > 3 @@ -510,7 +510,7 @@ class TestConversion(unittest.TestCase): self.assertEqual(r.height, self.colour.height) self.assertEqual(r.bands, self.colour.bands) - result = r.getpoint(10, 10) + result = r(10, 10) self.assertAlmostEqualObjects(result, [3, 3, 13]) test = self.mono > 3 @@ -520,9 +520,9 @@ class TestConversion(unittest.TestCase): self.assertEqual(r.bands, self.colour.bands) self.assertEqual(r.format, self.colour.format) self.assertEqual(r.interpretation, self.colour.interpretation) - result = r.getpoint(10, 10) + result = r(10, 10) self.assertAlmostEqualObjects(result, [2, 3, 4]) - result = r.getpoint(50, 50) + result = r(50, 50) self.assertAlmostEqualObjects(result, [1, 2, 3]) test = self.mono @@ -532,9 +532,9 @@ class TestConversion(unittest.TestCase): self.assertEqual(r.bands, self.colour.bands) self.assertEqual(r.format, self.colour.format) self.assertEqual(r.interpretation, self.colour.interpretation) - result = r.getpoint(10, 10) + result = r(10, 10) self.assertAlmostEqualObjects(result, [2, 3, 4], places = 1) - result = r.getpoint(50, 50) + result = r(50, 50) self.assertAlmostEqualObjects(result, [3.0, 4.9, 6.9], places = 1) def test_insert(self): @@ -548,12 +548,12 @@ class TestConversion(unittest.TestCase): self.assertEqual(r.height, main.height) self.assertEqual(r.bands, sub.bands) - a = r.getpoint(10, 10) - b = sub.getpoint(0, 0) + a = r(10, 10) + b = sub(0, 0) self.assertAlmostEqualObjects(a, b) - a = r.getpoint(0, 0) - b = main.getpoint(0, 0) * 3 + a = r(0, 0) + b = main(0, 0) * 3 self.assertAlmostEqualObjects(a, b) for x in all_formats: @@ -566,7 +566,7 @@ class TestConversion(unittest.TestCase): self.assertEqual(r.height, main.height + 10) self.assertEqual(r.bands, sub.bands) - a = r.getpoint(r.width - 5, 5) + a = r(r.width - 5, 5) self.assertAlmostEqualObjects(a, [100, 100, 100]) def test_msb(self): @@ -576,14 +576,14 @@ class TestConversion(unittest.TestCase): test = (self.colour + mx / 8.0).cast(fmt) im = test.msb() - before = test.getpoint(10, 10) + before = test(10, 10) predict = [int(x) >> ((size - 1) * 8) for x in before] - result = im.getpoint(10, 10) + result = im(10, 10) self.assertAlmostEqualObjects(result, predict) - before = test.getpoint(50, 50) + before = test(50, 50) predict = [int(x) >> ((size - 1) * 8) for x in before] - result = im.getpoint(50, 50) + result = im(50, 50) self.assertAlmostEqualObjects(result, predict) for fmt in signed_formats: @@ -592,14 +592,14 @@ class TestConversion(unittest.TestCase): test = (self.colour + mx / 8.0).cast(fmt) im = test.msb() - before = test.getpoint(10, 10) + before = test(10, 10) predict = [128 + (int(x) >> ((size - 1) * 8)) for x in before] - result = im.getpoint(10, 10) + result = im(10, 10) self.assertAlmostEqualObjects(result, predict) - before = test.getpoint(50, 50) + before = test(50, 50) predict = [128 + (int(x) >> ((size - 1) * 8)) for x in before] - result = im.getpoint(50, 50) + result = im(50, 50) self.assertAlmostEqualObjects(result, predict) for fmt in unsigned_formats: @@ -608,14 +608,14 @@ class TestConversion(unittest.TestCase): test = (self.colour + mx / 8.0).cast(fmt) im = test.msb(band = 1) - before = [test.getpoint(10, 10)[1]] + before = [test(10, 10)[1]] predict = [int(x) >> ((size - 1) * 8) for x in before] - result = im.getpoint(10, 10) + result = im(10, 10) self.assertAlmostEqualObjects(result, predict) - before = [test.getpoint(50, 50)[1]] + before = [test(50, 50)[1]] predict = [int(x) >> ((size - 1) * 8) for x in before] - result = im.getpoint(50, 50) + result = im(50, 50) self.assertAlmostEqualObjects(result, predict) def test_recomb(self): @@ -640,12 +640,12 @@ class TestConversion(unittest.TestCase): self.assertEqual(test.width, self.colour.width * 10) self.assertEqual(test.height, self.colour.height * 10) - before = im.getpoint(10, 10) - after = test.getpoint(10 + im.width * 2, 10 + im.width * 2) + before = im(10, 10) + after = test(10 + im.width * 2, 10 + im.width * 2) self.assertAlmostEqualObjects(before, after) - before = im.getpoint(50, 50) - after = test.getpoint(50 + im.width * 2, 50 + im.width * 2) + before = im(50, 50) + after = test(50 + im.width * 2, 50 + im.width * 2) self.assertAlmostEqualObjects(before, after) def test_rot45(self): @@ -655,8 +655,8 @@ class TestConversion(unittest.TestCase): im = test.cast(fmt) im2 = im.rot45() - before = im.getpoint(50, 50) - after = im2.getpoint(25, 50) + before = im(50, 50) + after = im2(25, 50) self.assertAlmostEqualObjects(before, after) for a, b in zip(rot45_angles, rot45_angle_bonds): @@ -672,8 +672,8 @@ class TestConversion(unittest.TestCase): im = test.cast(fmt) im2 = im.rot(Vips.Angle.D90) - before = im.getpoint(50, 50) - after = im2.getpoint(0, 50) + before = im(50, 50) + after = im2(0, 50) self.assertAlmostEqualObjects(before, after) for a, b in zip(rot_angles, rot_angle_bonds): @@ -701,8 +701,8 @@ class TestConversion(unittest.TestCase): self.assertEqual(im.width, test.width // 3) self.assertEqual(im.height, test.height // 3) - before = test.getpoint(60, 60) - after = im.getpoint(20, 20) + before = test(60, 60) + after = im(20, 20) self.assertAlmostEqualObjects(before, after) def test_zoom(self): @@ -713,8 +713,8 @@ class TestConversion(unittest.TestCase): self.assertEqual(im.width, test.width * 3) self.assertEqual(im.height, test.height * 3) - before = test.getpoint(50, 50) - after = im.getpoint(150, 150) + before = test(50, 50) + after = im(150, 150) self.assertAlmostEqualObjects(before, after) def test_wrap(self): @@ -725,12 +725,12 @@ class TestConversion(unittest.TestCase): self.assertEqual(im.width, test.width) self.assertEqual(im.height, test.height) - before = test.getpoint(0, 0) - after = im.getpoint(50, 50) + before = test(0, 0) + after = im(50, 50) self.assertAlmostEqualObjects(before, after) - before = test.getpoint(50, 50) - after = im.getpoint(0, 0) + before = test(50, 50) + after = im(0, 0) self.assertAlmostEqualObjects(before, after) if __name__ == '__main__': diff --git a/test/test_convolution.py b/test/test_convolution.py index ba3f6e56..b2916c2a 100755 --- a/test/test_convolution.py +++ b/test/test_convolution.py @@ -70,8 +70,8 @@ def conv(image, mask, x_position, y_position): s = 0.0 for x in range(0, mask.width): for y in range(0, mask.height): - m = mask.getpoint(x, y) - i = image.getpoint(x + x_position, y + y_position) + m = mask(x, y) + i = image(x + x_position, y + y_position) p = run_fn2(operator.mul, m, i) s = run_fn2(operator.add, s, p) @@ -119,11 +119,11 @@ class TestConvolution(unittest.TestCase): for prec in [Vips.Precision.INTEGER, Vips.Precision.FLOAT]: convolved = im.conv(msk, precision = prec) - result = convolved.getpoint(25, 50) + result = convolved(25, 50) true = conv(im, msk, 24, 49) self.assertAlmostEqualObjects(result, true) - result = convolved.getpoint(50, 50) + result = convolved(50, 50) true = conv(im, msk, 49, 49) self.assertAlmostEqualObjects(result, true) @@ -138,7 +138,7 @@ class TestConvolution(unittest.TestCase): combine = Vips.Combine.MAX, precision = prec) - result = convolved.getpoint(25, 50) + result = convolved(25, 50) true = compass(im, msk, 24, 49, times, max) self.assertAlmostEqualObjects(result, true) @@ -152,7 +152,7 @@ class TestConvolution(unittest.TestCase): combine = Vips.Combine.SUM, precision = prec) - result = convolved.getpoint(25, 50) + result = convolved(25, 50) true = compass(im, msk, 24, 49, times, operator.add) self.assertAlmostEqualObjects(result, true) @@ -172,8 +172,8 @@ class TestConvolution(unittest.TestCase): a = im.conv(gmask, precision = prec) b = im.convsep(gmask_sep, precision = prec) - a_point = a.getpoint(25, 50) - b_point = b.getpoint(25, 50) + a_point = a(25, 50) + b_point = b(25, 50) self.assertAlmostEqualObjects(a_point, b_point, places = 1) @@ -210,8 +210,8 @@ class TestConvolution(unittest.TestCase): a = im.conv(gmask, precision = prec) b = im.gaussblur(sigma, min_ampl = 0.2, precision = prec) - a_point = a.getpoint(25, 50) - b_point = b.getpoint(25, 50) + a_point = a(25, 50) + b_point = b(25, 50) self.assertAlmostEqualObjects(a_point, b_point, places = 1) diff --git a/test/test_create.py b/test/test_create.py index 1b08f7b4..6fdb71d2 100755 --- a/test/test_create.py +++ b/test/test_create.py @@ -43,7 +43,7 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.format, Vips.BandFormat.UCHAR) self.assertEqual(im.bands, 1) for i in range (0, 100): - pixel = im.getpoint(i, i) + pixel = im(i, i) self.assertEqual(len(pixel), 1) self.assertEqual(pixel[0], 0) @@ -54,7 +54,7 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.format, Vips.BandFormat.UCHAR) self.assertEqual(im.bands, 3) for i in range (0, 100): - pixel = im.getpoint(i, i) + pixel = im(i, i) self.assertEqual(len(pixel), 3) self.assertAlmostEqualObjects(pixel, [0, 0, 0]) @@ -65,11 +65,11 @@ class TestCreate(unittest.TestCase): self.assertEqual(lut.width, 256) self.assertEqual(lut.height, 1) self.assertEqual(lut.bands, 1) - p = lut.getpoint(0, 0) + p = lut(0, 0) self.assertEqual(p[0], 0.0) - p = lut.getpoint(255, 0) + p = lut(255, 0) self.assertEqual(p[0], 100.0) - p = lut.getpoint(10, 0) + p = lut(10, 0) self.assertEqual(p[0], 100 * 10.0 / 255.0) M = Vips.Image.new_from_array([[0, 0, 100], @@ -79,9 +79,9 @@ class TestCreate(unittest.TestCase): self.assertEqual(lut.width, 256) self.assertEqual(lut.height, 1) self.assertEqual(lut.bands, 2) - p = lut.getpoint(0, 0) + p = lut(0, 0) self.assertAlmostEqualObjects(p, [0.0, 100.0]) - p = lut.getpoint(64, 0) + p = lut(64, 0) self.assertAlmostEqualObjects(p, [5.0, 95.0]) def test_eye(self): @@ -118,7 +118,7 @@ class TestCreate(unittest.TestCase): total = im.avg() * im.width * im.height scale = im.get("scale") self.assertEqual(total, scale) - p = im.getpoint(im.width / 2, im.height / 2) + p = im(im.width / 2, im.height / 2) self.assertEqual(p[0], 20.0) im = Vips.Image.gaussmat(1, 0.1, @@ -131,7 +131,7 @@ class TestCreate(unittest.TestCase): total = im.avg() * im.width * im.height scale = im.get("scale") self.assertEqual(total, scale) - p = im.getpoint(im.width / 2, im.height / 2) + p = im(im.width / 2, im.height / 2) self.assertEqual(p[0], 1.0) def test_gaussnoise(self): @@ -160,13 +160,13 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.bands, 1) self.assertEqual(im.format, Vips.BandFormat.FLOAT) - p = im.getpoint(0, 0) + p = im(0, 0) self.assertEqual(p[0], 0.0) - p = im.getpoint(99, 0) + p = im(99, 0) self.assertEqual(p[0], 1.0) - p = im.getpoint(0, 89) + p = im(0, 89) self.assertEqual(p[0], 0.0) - p = im.getpoint(99, 89) + p = im(99, 89) self.assertEqual(p[0], 1.0) im = Vips.Image.grey(100, 90, uchar = True) @@ -175,13 +175,13 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.bands, 1) self.assertEqual(im.format, Vips.BandFormat.UCHAR) - p = im.getpoint(0, 0) + p = im(0, 0) self.assertEqual(p[0], 0) - p = im.getpoint(99, 0) + p = im(99, 0) self.assertEqual(p[0], 255) - p = im.getpoint(0, 89) + p = im(0, 89) self.assertEqual(p[0], 0) - p = im.getpoint(99, 89) + p = im(99, 89) self.assertEqual(p[0], 255) def test_identity(self): @@ -191,11 +191,11 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.bands, 1) self.assertEqual(im.format, Vips.BandFormat.UCHAR) - p = im.getpoint(0, 0) + p = im(0, 0) self.assertEqual(p[0], 0.0) - p = im.getpoint(255, 0) + p = im(255, 0) self.assertEqual(p[0], 255.0) - p = im.getpoint(128, 0) + p = im(128, 0) self.assertEqual(p[0], 128.0) im = Vips.Image.identity(ushort = True) @@ -204,11 +204,11 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.bands, 1) self.assertEqual(im.format, Vips.BandFormat.USHORT) - p = im.getpoint(0, 0) + p = im(0, 0) self.assertEqual(p[0], 0) - p = im.getpoint(99, 0) + p = im(99, 0) self.assertEqual(p[0], 99) - p = im.getpoint(65535, 0) + p = im(65535, 0) self.assertEqual(p[0], 65535) def test_invertlut(self): @@ -221,15 +221,15 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.bands, 3) self.assertEqual(im.format, Vips.BandFormat.DOUBLE) - p = im.getpoint(0, 0) + p = im(0, 0) self.assertAlmostEqualObjects(p, [0, 0, 0]) - p = im.getpoint(255, 0) + p = im(255, 0) self.assertAlmostEqualObjects(p, [1, 1, 1]) - p = im.getpoint(0.2 * 255, 0) + p = im(0.2 * 255, 0) self.assertAlmostEqual(p[0], 0.1, places = 2) - p = im.getpoint(0.3 * 255, 0) + p = im(0.3 * 255, 0) self.assertAlmostEqual(p[1], 0.1, places = 2) - p = im.getpoint(0.1 * 255, 0) + p = im(0.1 * 255, 0) self.assertAlmostEqual(p[2], 0.1, places = 2) def test_logmat(self): @@ -242,7 +242,7 @@ class TestCreate(unittest.TestCase): total = im.avg() * im.width * im.height scale = im.get("scale") self.assertEqual(total, scale) - p = im.getpoint(im.width / 2, im.height / 2) + p = im(im.width / 2, im.height / 2) self.assertEqual(p[0], 20.0) im = Vips.Image.logmat(1, 0.1, @@ -255,7 +255,7 @@ class TestCreate(unittest.TestCase): total = im.avg() * im.width * im.height scale = im.get("scale") self.assertEqual(total, scale) - p = im.getpoint(im.width / 2, im.height / 2) + p = im(im.width / 2, im.height / 2) self.assertEqual(p[0], 1.0) def test_mask_butterworth_band(self): @@ -265,7 +265,7 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.bands, 1) self.assertEqual(im.format, Vips.BandFormat.FLOAT) self.assertAlmostEqual(im.max(), 1, places = 2) - p = im.getpoint(32, 32) + p = im(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, @@ -275,9 +275,9 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.bands, 1) self.assertEqual(im.format, Vips.BandFormat.UCHAR) self.assertEqual(im.max(), 255) - p = im.getpoint(32, 32) + p = im(32, 32) self.assertEqual(p[0], 255.0) - p = im.getpoint(64, 64) + p = im(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, @@ -288,9 +288,9 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.bands, 1) self.assertEqual(im.format, Vips.BandFormat.UCHAR) self.assertEqual(im.max(), 255) - p = im.getpoint(32, 32) + p = im(32, 32) self.assertEqual(p[0], 255.0) - p = im.getpoint(64, 64) + p = im(64, 64) self.assertNotEqual(p[0], 255) def test_mask_butterworth(self): @@ -301,7 +301,7 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.bands, 1) self.assertEqual(im.format, Vips.BandFormat.FLOAT) self.assertAlmostEqual(im.min(), 0, places = 2) - p = im.getpoint(0, 0) + p = im(0, 0) self.assertEqual(p[0], 0.0) v, x, y = im.maxpos() self.assertEqual(x, 64) @@ -314,7 +314,7 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.bands, 1) self.assertEqual(im.format, Vips.BandFormat.UCHAR) self.assertAlmostEqual(im.min(), 0, places = 2) - p = im.getpoint(64, 64) + p = im(64, 64) self.assertEqual(p[0], 255) def test_mask_butterworth_ring(self): @@ -324,7 +324,7 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.height, 128) self.assertEqual(im.bands, 1) self.assertEqual(im.format, Vips.BandFormat.FLOAT) - p = im.getpoint(45, 0) + p = im(45, 0) self.assertAlmostEqual(p[0], 1.0, places = 4) v, x, y = im.minpos() self.assertEqual(x, 64) @@ -344,7 +344,7 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.bands, 1) self.assertEqual(im.format, Vips.BandFormat.FLOAT) self.assertAlmostEqual(im.max(), 1, places = 2) - p = im.getpoint(32, 32) + p = im(32, 32) self.assertEqual(p[0], 1.0) def test_mask_gaussian(self): @@ -355,7 +355,7 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.bands, 1) self.assertEqual(im.format, Vips.BandFormat.FLOAT) self.assertAlmostEqual(im.min(), 0, places = 2) - p = im.getpoint(0, 0) + p = im(0, 0) self.assertEqual(p[0], 0.0) def test_mask_gaussian_ring(self): @@ -365,7 +365,7 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.height, 128) self.assertEqual(im.bands, 1) self.assertEqual(im.format, Vips.BandFormat.FLOAT) - p = im.getpoint(45, 0) + p = im(45, 0) self.assertAlmostEqual(p[0], 1.0, places = 3) def test_mask_ideal_band(self): @@ -375,7 +375,7 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.bands, 1) self.assertEqual(im.format, Vips.BandFormat.FLOAT) self.assertAlmostEqual(im.max(), 1, places = 2) - p = im.getpoint(32, 32) + p = im(32, 32) self.assertEqual(p[0], 1.0) def test_mask_ideal(self): @@ -386,7 +386,7 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.bands, 1) self.assertEqual(im.format, Vips.BandFormat.FLOAT) self.assertAlmostEqual(im.min(), 0, places = 2) - p = im.getpoint(0, 0) + p = im(0, 0) self.assertEqual(p[0], 0.0) def test_mask_gaussian_ring(self): @@ -396,7 +396,7 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.height, 128) self.assertEqual(im.bands, 1) self.assertEqual(im.format, Vips.BandFormat.FLOAT) - p = im.getpoint(45, 0) + p = im(45, 0) self.assertAlmostEqual(p[0], 1.0, places = 3) def test_sines(self): @@ -429,7 +429,7 @@ class TestCreate(unittest.TestCase): self.assertEqual(im.format, Vips.BandFormat.UINT) self.assertEqual(im.width, 128) self.assertEqual(im.height, 128) - p = im.getpoint(45, 35) + p = im(45, 35) self.assertAlmostEqualObjects(p, [45, 35]) def test_zone(self): diff --git a/test/test_draw.py b/test/test_draw.py index bf607497..0a830983 100755 --- a/test/test_draw.py +++ b/test/test_draw.py @@ -38,21 +38,21 @@ class TestDraw(unittest.TestCase): def test_draw_circle(self): im = Vips.Image.black(100, 100) im = im.draw_circle(100, 50, 50, 25) - pixel = im.getpoint(25, 50) + pixel = im(25, 50) self.assertEqual(len(pixel), 1) self.assertEqual(pixel[0], 100) - pixel = im.getpoint(26, 50) + pixel = im(26, 50) self.assertEqual(len(pixel), 1) self.assertEqual(pixel[0], 0) im = Vips.Image.black(100, 100) im = im.draw_circle(100, 50, 50, 25, fill = True) - pixel = im.getpoint(25, 50) + pixel = im(25, 50) self.assertEqual(len(pixel), 1) self.assertEqual(pixel[0], 100) - pixel = im.getpoint(26, 50) + pixel = im(26, 50) self.assertEqual(pixel[0], 100) - pixel = im.getpoint(24, 50) + pixel = im(24, 50) self.assertEqual(pixel[0], 0) def test_draw_flood(self): @@ -82,10 +82,10 @@ class TestDraw(unittest.TestCase): def test_draw_line(self): im = Vips.Image.black(100, 100) im = im.draw_line(100, 0, 0, 100, 0) - pixel = im.getpoint(0, 0) + pixel = im(0, 0) self.assertEqual(len(pixel), 1) self.assertEqual(pixel[0], 100) - pixel = im.getpoint(0, 1) + pixel = im(0, 1) self.assertEqual(len(pixel), 1) self.assertEqual(pixel[0], 0) diff --git a/test/test_foreign.py b/test/test_foreign.py index b3922494..52e95165 100755 --- a/test/test_foreign.py +++ b/test/test_foreign.py @@ -96,7 +96,7 @@ class TestForeign(unittest.TestCase): return def jpeg_valid(self, im): - a = im.getpoint(10, 10) + a = im(10, 10) self.assertAlmostEqualObjects(a, [6, 5, 3]) profile = im.get_value("icc-profile-data") self.assertEqual(len(profile), 1352) @@ -115,7 +115,7 @@ class TestForeign(unittest.TestCase): return def png_valid(self, im): - a = im.getpoint(10, 10) + a = im(10, 10) self.assertAlmostEqualObjects(a, [38671.0, 33914.0, 26762.0]) self.assertEqual(im.width, 290) self.assertEqual(im.height, 442) @@ -132,7 +132,7 @@ class TestForeign(unittest.TestCase): return def tiff_valid(self, im): - a = im.getpoint(10, 10) + a = im(10, 10) self.assertAlmostEqualObjects(a, [38671.0, 33914.0, 26762.0]) self.assertEqual(im.width, 290) self.assertEqual(im.height, 442) @@ -159,7 +159,7 @@ class TestForeign(unittest.TestCase): return def gif_valid(self, im): - a = im.getpoint(10, 10) + a = im(10, 10) self.assertAlmostEqual(a, [33, 33, 33]) self.assertEqual(im.width, 159) self.assertEqual(im.height, 203) @@ -174,7 +174,7 @@ class TestForeign(unittest.TestCase): return def webp_valid(self, im): - a = im.getpoint(10, 10) + a = im(10, 10) self.assertAlmostEqualObjects(a, [71, 166, 236]) self.assertEqual(im.width, 550) self.assertEqual(im.height, 368) @@ -186,7 +186,7 @@ class TestForeign(unittest.TestCase): def test_analyzeload(self): def analyze_valid(self, im): - a = im.getpoint(10, 10) + a = im(10, 10) self.assertAlmostEqual(a[0], 3335) self.assertEqual(im.width, 128) self.assertEqual(im.height, 8064) @@ -200,7 +200,7 @@ class TestForeign(unittest.TestCase): return def matlab_valid(self, im): - a = im.getpoint(10, 10) + a = im(10, 10) self.assertAlmostEqualObjects(a, [38671.0, 33914.0, 26762.0]) self.assertEqual(im.width, 290) self.assertEqual(im.height, 442) @@ -214,7 +214,7 @@ class TestForeign(unittest.TestCase): return def exr_valid(self, im): - a = im.getpoint(10, 10) + a = im(10, 10) self.assertAlmostEqualObjects(a, [0.124512, 0.159668, 0.040375, 1.0], places = 5) @@ -230,7 +230,7 @@ class TestForeign(unittest.TestCase): return def fits_valid(self, im): - a = im.getpoint(10, 10) + a = im(10, 10) self.assertAlmostEqualObjects(a, [-0.165013, -0.148553, 1.09122, -0.942242], places = 5) @@ -247,7 +247,7 @@ class TestForeign(unittest.TestCase): return def openslide_valid(self, im): - a = im.getpoint(10, 10) + a = im(10, 10) self.assertAlmostEqualObjects(a, [244, 250, 243, 255]) self.assertEqual(im.width, 2220) self.assertEqual(im.height, 2967) diff --git a/test/test_histogram.py b/test/test_histogram.py index ba63c681..ae6bbe32 100755 --- a/test/test_histogram.py +++ b/test/test_histogram.py @@ -42,7 +42,7 @@ class TestHistogram(unittest.TestCase): cum = im.hist_cum() - p = cum.getpoint(255, 0) + p = cum(255, 0) self.assertEqual(p[0], sum) def test_hist_equal(self):