fix getpoint(0,0)

and add more tests
This commit is contained in:
John Cupitt 2014-09-15 09:06:36 +01:00
parent 876a7538af
commit cc599844d2
4 changed files with 53 additions and 31 deletions

6
TODO
View File

@ -1,11 +1,11 @@
- python:
- this is very annoying:
- try
real = im.complexget(Vips.OperationComplexget.REAL)
python test_arithmetic.py -v TestArithmetic.test_histfind
define im.real() and im.imag()
segv
- could import like this:

View File

@ -151,17 +151,17 @@ vips_getpoint_class_init( VipsGetpointClass *class )
VIPS_ARG_INT( class, "x", 5,
_( "x" ),
_( "Getpoint to read from" ),
_( "Point to read" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsGetpoint, x ),
1, RANGE, 1 );
0, RANGE, 0 );
VIPS_ARG_INT( class, "y", 6,
_( "y" ),
_( "Getpoint to read from" ),
_( "Point to read" ),
VIPS_ARGUMENT_REQUIRED_INPUT,
G_STRUCT_OFFSET( VipsGetpoint, y ),
1, RANGE, 1 );
0, RANGE, 0 );
}

View File

@ -268,43 +268,52 @@ class TestArithmetic(unittest.TestCase):
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_deviate(self):
im = Vips.Image.black(50, 100)
test = im.insert(im + 100, 50, 0, expand = True)
for fmt in noncomplex_formats:
self.assertAlmostEqual(test.cast(fmt).deviate(), 50, places = 2)
def test_polar(self):
im = Vips.Image.black(100, 100) + 100
im = im.complexform(im)
im = im.complex(Vips.OperationComplex.POLAR)
im = im.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)
self.assertAlmostEqual(im.real().avg(), 100 * 2 ** 0.5)
self.assertAlmostEqual(im.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)
im = im.rect()
real = im.complexget(Vips.OperationComplexget.REAL)
self.assertAlmostEqual(real.avg(), 100)
imag = im.complexget(Vips.OperationComplexget.IMAG)
self.assertAlmostEqual(imag.avg(), 100)
self.assertAlmostEqual(im.real().avg(), 100)
self.assertAlmostEqual(im.imag().avg(), 100)
def test_conjugate(self):
im = Vips.Image.black(100, 100) + 100
im = im.complexform(im)
im = im.complex(Vips.OperationComplex.CONJ)
im = im.conj()
real = im.complexget(Vips.OperationComplexget.REAL)
self.assertAlmostEqual(real.avg(), 100)
imag = im.complexget(Vips.OperationComplexget.IMAG)
self.assertAlmostEqual(imag.avg(), -100)
self.assertAlmostEqual(im.real().avg(), 100)
self.assertAlmostEqual(im.imag().avg(), -100)
def test_histfind(self):
im = Vips.Image.black(50, 100)
test = im.insert(im + 100, 50, 0, expand = True)
for fmt in all_formats:
hist = test.cast(fmt).hist_find()
self.assertAlmostEqualObjects(hist.getpoint(0,0), [5000])
self.assertAlmostEqualObjects(hist.getpoint(100,0), [5000])
self.assertAlmostEqualObjects(hist.getpoint(12,0), [0])
if __name__ == '__main__':
unittest.main()

View File

@ -255,10 +255,6 @@ def vips_image_new_from_array(cls, array, scale = 1, offset = 0):
return image
# this is a class method
def vips_black(cls, width, height, **kwargs):
return _call_base("black", [width, height], kwargs)
def vips_image_getattr(self, name):
logging.debug('Image.__getattr__ %s' % name)
@ -403,6 +399,21 @@ def vips_abs(self):
def vips_invert(self):
return self ^ -1
def vips_real(self):
return self.complexget(Vips.OperationComplexget.REAL)
def vips_imag(self):
return self.complexget(Vips.OperationComplexget.IMAG)
def vips_polar(self):
return self.complex(Vips.OperationComplex.POLAR)
def vips_rect(self):
return self.complex(Vips.OperationComplex.RECT)
def vips_conj(self):
return self.complex(Vips.OperationComplex.CONJ)
# paste our methods into Vips.Image
# class methods
@ -410,9 +421,6 @@ setattr(Vips.Image, 'new_from_file', classmethod(vips_image_new_from_file))
setattr(Vips.Image, 'new_from_buffer', classmethod(vips_image_new_from_buffer))
setattr(Vips.Image, 'new_from_array', classmethod(vips_image_new_from_array))
# yuk, we should run these via a metaclass somehow
#setattr(Vips.Image, 'black', classmethod(vips_black))
# Search for all VipsOperation which don't have an input image object ... these
# become class methods
@ -459,6 +467,11 @@ Vips.Image.write_to_buffer = vips_image_write_to_buffer
# a few useful things
Vips.Image.floor = vips_floor
Vips.Image.bandsplit = vips_bandsplit
Vips.Image.real = vips_real
Vips.Image.imag = vips_imag
Vips.Image.polar = vips_polar
Vips.Image.rect = vips_rect
Vips.Image.conj = vips_conj
# operator overloads
Vips.Image.__getattr__ = vips_image_getattr