diff --git a/TODO b/TODO index 95787836..87554027 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,12 @@ - python: + - this is very annoying: + + real = im.complexget(Vips.OperationComplexget.REAL) + + define im.real() and im.imag() + - could import like this: from gi.repository import Vips diff --git a/python/test_arithmetic.py b/python/test_arithmetic.py index 668ef323..258c2439 100755 --- a/python/test_arithmetic.py +++ b/python/test_arithmetic.py @@ -264,5 +264,47 @@ class TestArithmetic(unittest.TestCase): # test the rest of VipsArithmetic + def test_avg(self): + im = Vips.Image.black(50, 100) + test = im.insert(im + 100, 50, 0, expand = True) + + test.write_to_file("x.v") + + for fmt in all_formats: + self.assertAlmostEqual(test.cast(fmt).avg(), 50) + + def test_polar(self): + im = Vips.Image.black(100, 100) + 100 + im = im.complexform(im) + + im = im.complex(Vips.OperationComplex.POLAR) + + real = im.complexget(Vips.OperationComplexget.REAL) + self.assertAlmostEqual(real.avg(), 100 * 2 ** 0.5) + imag = im.complexget(Vips.OperationComplexget.IMAG) + self.assertAlmostEqual(imag.avg(), 45) + + def test_rect(self): + im = Vips.Image.black(100, 100) + im = (im + 100 * 2 ** 0.5).complexform(im + 45) + + im = im.complex(Vips.OperationComplex.RECT) + + real = im.complexget(Vips.OperationComplexget.REAL) + self.assertAlmostEqual(real.avg(), 100) + imag = im.complexget(Vips.OperationComplexget.IMAG) + self.assertAlmostEqual(imag.avg(), 100) + + def test_conjugate(self): + im = Vips.Image.black(100, 100) + 100 + im = im.complexform(im) + + im = im.complex(Vips.OperationComplex.CONJ) + + real = im.complexget(Vips.OperationComplexget.REAL) + self.assertAlmostEqual(real.avg(), 100) + imag = im.complexget(Vips.OperationComplexget.IMAG) + self.assertAlmostEqual(imag.avg(), -100) + if __name__ == '__main__': unittest.main()