Add unit test for vips_mosaic / vips_globalbalance

This commit is contained in:
Kleis Auke Wolthuizen 2020-06-18 14:42:55 +02:00
parent 4b5db786f0
commit 541e58610b
10 changed files with 54 additions and 0 deletions

View File

@ -40,6 +40,17 @@ BMP_FILE = os.path.join(IMAGES, "MARBLES.BMP")
NIFTI_FILE = os.path.join(IMAGES, "avg152T1_LR_nifti.nii.gz")
ICO_FILE = os.path.join(IMAGES, "favicon.ico")
HEIC_FILE = os.path.join(IMAGES, "heic-orientation-6.heic")
MOSAIC_FILES = [os.path.join(IMAGES, "cd1.1.jpg"), os.path.join(IMAGES, "cd1.2.jpg"),
os.path.join(IMAGES, "cd2.1.jpg"), os.path.join(IMAGES, "cd2.2.jpg"),
os.path.join(IMAGES, "cd3.1.jpg"), os.path.join(IMAGES, "cd3.2.jpg"),
os.path.join(IMAGES, "cd4.1.jpg"), os.path.join(IMAGES, "cd4.2.jpg")]
MOSAIC_MARKS = [[489, 140], [66, 141],
[453, 40], [15, 43],
[500, 122], [65, 121],
[495, 58], [40, 57]]
MOSAIC_VERTICAL_MARKS = [[388, 44], [364, 346],
[384, 17], [385, 629],
[527, 42], [503, 959]]
unsigned_formats = [pyvips.BandFormat.UCHAR,
pyvips.BandFormat.USHORT,

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -0,0 +1,43 @@
# vim: set fileencoding=utf-8 :
import pytest
import pyvips
from helpers import MOSAIC_FILES, MOSAIC_MARKS, MOSAIC_VERTICAL_MARKS
class TestMosaicing:
def test_mosaic(self):
# ported from https://github.com/libvips/nip2/tree/master/share/nip2/data/examples/1_point_mosaic
mosaiced_image = None
for i in range(0, len(MOSAIC_FILES), 2):
files = MOSAIC_FILES[i:i + 2]
marks = MOSAIC_MARKS[i:i + 2]
im = pyvips.Image.new_from_file(files[0])
sec_im = pyvips.Image.new_from_file(files[1])
horizontal_part = im.mosaic(sec_im, pyvips.Direction.HORIZONTAL,
marks[0][0], marks[0][1], marks[1][0], marks[1][1])
if mosaiced_image is None:
mosaiced_image = horizontal_part
else:
vertical_marks = MOSAIC_VERTICAL_MARKS[i - 2:i]
mosaiced_image = mosaiced_image.mosaic(horizontal_part, pyvips.Direction.VERTICAL,
vertical_marks[1][0], vertical_marks[1][1],
vertical_marks[0][0], vertical_marks[0][1])
mosaiced_image = mosaiced_image.globalbalance()
# Uncomment to see output file
# mosaiced_image.write_to_file('1-pt-mosaic.jpg')
# hard to test much more than this
assert mosaiced_image.width == 1005
assert mosaiced_image.height == 1295
assert mosaiced_image.interpretation == pyvips.Interpretation.B_W
assert mosaiced_image.format == pyvips.BandFormat.FLOAT
assert mosaiced_image.bands == 1
if __name__ == '__main__':
pytest.main()