better Vips.py install
more work on test_convolution
This commit is contained in:
parent
649c0afb61
commit
71bb0e81d1
10
TODO
10
TODO
@ -1,3 +1,13 @@
|
|||||||
|
- something screwy in compass def?
|
||||||
|
|
||||||
|
$ python2 ./test_convolution.py TestConvolution.test_x
|
||||||
|
|
||||||
|
- configure should check for pygobject too
|
||||||
|
|
||||||
|
PKG_CHECK_MODULES(PYTHON, [pygobject-3.0 >= $PYGOBJECT_REQUIRED])
|
||||||
|
|
||||||
|
have separate conditionals for old py and new py
|
||||||
|
|
||||||
- use vips_resize() in vipsthumbnail?
|
- use vips_resize() in vipsthumbnail?
|
||||||
|
|
||||||
should the sharpening filter be selectable?
|
should the sharpening filter be selectable?
|
||||||
|
@ -755,7 +755,9 @@ if test x"$with_python" != "xno"; then
|
|||||||
with_python=no
|
with_python=no
|
||||||
AC_MSG_WARN([C++ is off, disabling Python binding])
|
AC_MSG_WARN([C++ is off, disabling Python binding])
|
||||||
else
|
else
|
||||||
AM_PATH_PYTHON(2.2,,
|
AM_PATH_PYTHON(2.7,
|
||||||
|
[pyoverridesdir="\$(pyexecdir)/gi/overrides"
|
||||||
|
AC_SUBST(pyoverridesdir)],
|
||||||
[with_python=no
|
[with_python=no
|
||||||
AC_MSG_WARN([Python not found; disabling Python binding])])
|
AC_MSG_WARN([Python not found; disabling Python binding])])
|
||||||
fi
|
fi
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
pygioverridesdir = $(pyexecdir)/gi/overrides
|
vips_overridesdir = $(pyoverridesdir)
|
||||||
|
vips_overrides_PYTHON = Vips.py
|
||||||
pygioverrides_PYTHON = \
|
|
||||||
Vips.py
|
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
README.md
|
README.md
|
||||||
@ -10,7 +8,7 @@ EXTRA_DIST = \
|
|||||||
# source tree; Python does not accept the extensions and modules in different
|
# source tree; Python does not accept the extensions and modules in different
|
||||||
# paths
|
# paths
|
||||||
build_pylinks:
|
build_pylinks:
|
||||||
for f in $(pygioverrides_PYTHON); do \
|
for f in $(vips_overrides_PYTHON); do \
|
||||||
[ -e $(builddir)/$$f ] || $(LN_S) $(srcdir)/$$f $(builddir)/$$f; \
|
[ -e $(builddir)/$$f ] || $(LN_S) $(srcdir)/$$f $(builddir)/$$f; \
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ from builtins import range
|
|||||||
from numbers import Number
|
from numbers import Number
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
import operator
|
||||||
import math
|
import math
|
||||||
|
|
||||||
#import logging
|
#import logging
|
||||||
@ -56,10 +57,20 @@ def conv(image, mask, x_position, y_position):
|
|||||||
for y in range(0, mask.height):
|
for y in range(0, mask.height):
|
||||||
m = mask.getpoint(x, y)
|
m = mask.getpoint(x, y)
|
||||||
i = image.getpoint(x + x_position, y + y_position)
|
i = image.getpoint(x + x_position, y + y_position)
|
||||||
p = run_fn2(lambda a, b: a * b, m, i)
|
p = run_fn2(operator.mul, m, i)
|
||||||
s = run_fn2(lambda a, b: a + b, s, p)
|
s = run_fn2(operator.add, s, p)
|
||||||
|
|
||||||
return run_fn2(lambda a, b: a / b, s, mask.get_scale())
|
return run_fn2(operator.div, s, mask.get_scale())
|
||||||
|
|
||||||
|
def compass(image, mask, x_position, y_position, n_rot, fn):
|
||||||
|
acc = []
|
||||||
|
for i in range(0, n_rot):
|
||||||
|
result = conv(image, mask, x_position, y_position)
|
||||||
|
result = run_fn(abs, result)
|
||||||
|
acc.append(result)
|
||||||
|
mask = mask.rot45()
|
||||||
|
|
||||||
|
return reduce(lambda a, b: run_fn2(fn, a, b), acc)
|
||||||
|
|
||||||
class TestConvolution(unittest.TestCase):
|
class TestConvolution(unittest.TestCase):
|
||||||
# test a pair of things which can be lists for approx. equality
|
# test a pair of things which can be lists for approx. equality
|
||||||
@ -73,15 +84,19 @@ class TestConvolution(unittest.TestCase):
|
|||||||
self.colour = im * [1, 2, 3] + [2, 3, 4]
|
self.colour = im * [1, 2, 3] + [2, 3, 4]
|
||||||
self.mono = self.colour.extract_band(1)
|
self.mono = self.colour.extract_band(1)
|
||||||
self.all_images = [self.mono, self.colour]
|
self.all_images = [self.mono, self.colour]
|
||||||
sharp = Vips.Image.new_from_array([[-1, -1, -1],
|
self.sharp = Vips.Image.new_from_array([[-1, -1, -1],
|
||||||
[-1, 16, -1],
|
[-1, 16, -1],
|
||||||
[-1, -1, -1]], scale = 8)
|
[-1, -1, -1]], scale = 8)
|
||||||
blur = Vips.Image.new_from_array([[1, 1, 1],
|
self.blur = Vips.Image.new_from_array([[1, 1, 1],
|
||||||
[1, 1, 1],
|
[1, 1, 1],
|
||||||
[1, 1, 1]], scale = 9)
|
[1, 1, 1]], scale = 9)
|
||||||
line = Vips.Image.new_from_array([[1, 1, 1], [-2, -2, -2], [1, 1, 1]])
|
self.line = Vips.Image.new_from_array([[ 1, 1, 1],
|
||||||
sobel = Vips.Image.new_from_array([[1, 2, 1], [0, 0, 0], [-1, -2, -1]])
|
[-2, -2, -2],
|
||||||
self.all_masks = [sharp, blur, line, sobel]
|
[ 1, 1, 1]])
|
||||||
|
self.sobel = Vips.Image.new_from_array([[ 1, 2, 1],
|
||||||
|
[ 0, 0, 0],
|
||||||
|
[-1, -2, -1]])
|
||||||
|
self.all_masks = [self.sharp, self.blur, self.line, self.sobel]
|
||||||
|
|
||||||
def test_conv(self):
|
def test_conv(self):
|
||||||
for im in self.all_images:
|
for im in self.all_images:
|
||||||
@ -97,7 +112,29 @@ class TestConvolution(unittest.TestCase):
|
|||||||
true = conv(im, msk, 49, 49)
|
true = conv(im, msk, 49, 49)
|
||||||
self.assertAlmostEqualObjects(result, true)
|
self.assertAlmostEqualObjects(result, true)
|
||||||
|
|
||||||
|
def test_x(self):
|
||||||
|
im = self.mono
|
||||||
|
msk = self.sobel
|
||||||
|
|
||||||
|
result = conv(im, msk, 24, 49)
|
||||||
|
msk = msk.rot45()
|
||||||
|
|
||||||
|
result = conv(im, msk, 24, 49)
|
||||||
|
msk = msk.rot45()
|
||||||
|
|
||||||
|
def test_compass(self):
|
||||||
|
for im in self.all_images:
|
||||||
|
for msk in self.all_masks:
|
||||||
|
for prec in [Vips.Precision.INTEGER, Vips.Precision.FLOAT]:
|
||||||
|
convolved = im.compass(msk,
|
||||||
|
times = 3,
|
||||||
|
angle = Vips.Angle45.D45,
|
||||||
|
combine = Vips.Combine.MAX,
|
||||||
|
precision = prec)
|
||||||
|
|
||||||
|
result = convolved.getpoint(25, 50)
|
||||||
|
true = compass(im, msk, 24, 49, 3, max)
|
||||||
|
self.assertAlmostEqualObjects(result, true)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user