2020-06-18 14:42:55 +02:00
|
|
|
# vim: set fileencoding=utf-8 :
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
import pyvips
|
|
|
|
from helpers import MOSAIC_FILES, MOSAIC_MARKS, MOSAIC_VERTICAL_MARKS
|
|
|
|
|
|
|
|
class TestMosaicing:
|
2021-02-05 18:14:48 +01:00
|
|
|
|
|
|
|
def test_lrmerge(self):
|
|
|
|
left = pyvips.Image.new_from_file(MOSAIC_FILES[0])
|
|
|
|
right = pyvips.Image.new_from_file(MOSAIC_FILES[1])
|
|
|
|
join = left.merge(right, 'horizontal', 10 - left.width, 0)
|
|
|
|
|
|
|
|
assert join.width == left.width + right.width - 10
|
|
|
|
assert join.height == max(left.height, right.height)
|
|
|
|
assert join.bands == 1
|
|
|
|
|
|
|
|
def test_tbmerge(self):
|
|
|
|
top = pyvips.Image.new_from_file(MOSAIC_FILES[0])
|
|
|
|
bottom = pyvips.Image.new_from_file(MOSAIC_FILES[2])
|
|
|
|
join = top.merge(bottom, 'vertical', 0, 10 - top.height)
|
|
|
|
|
|
|
|
assert join.width == max(top.width, bottom.width)
|
|
|
|
assert join.height == top.height + bottom.height - 10
|
|
|
|
assert join.bands == 1
|
|
|
|
|
|
|
|
def test_lrmosaic(self):
|
|
|
|
left = pyvips.Image.new_from_file(MOSAIC_FILES[0])
|
|
|
|
right = pyvips.Image.new_from_file(MOSAIC_FILES[1])
|
|
|
|
join = left.mosaic(right, 'horizontal', left.width - 30, 0, 30, 0)
|
|
|
|
|
|
|
|
assert join.width == 1014
|
|
|
|
assert join.height == 379
|
|
|
|
assert join.bands == 1
|
|
|
|
|
|
|
|
def test_tbmosaic(self):
|
|
|
|
top = pyvips.Image.new_from_file(MOSAIC_FILES[0])
|
|
|
|
bottom = pyvips.Image.new_from_file(MOSAIC_FILES[2])
|
|
|
|
join = top.mosaic(bottom, 'vertical', 0, top.height - 30, 0, 30)
|
|
|
|
|
|
|
|
assert join.width == 542
|
|
|
|
assert join.height == 688
|
|
|
|
assert join.bands == 1
|
|
|
|
|
2020-06-18 14:42:55 +02:00
|
|
|
def test_mosaic(self):
|
|
|
|
# ported from https://github.com/libvips/nip2/tree/master/share/nip2/data/examples/1_point_mosaic
|
|
|
|
|
|
|
|
mosaiced_image = None
|
|
|
|
|
2021-02-06 16:42:31 +01:00
|
|
|
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])
|
|
|
|
|
|
|
|
# Uncomment to see output file
|
|
|
|
#mosaiced_image.write_to_file('after.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.bands == 1
|
|
|
|
|
|
|
|
def test_globalbalance(self):
|
|
|
|
mosaiced_image = None
|
|
|
|
|
2020-06-18 14:42:55 +02:00
|
|
|
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])
|
2020-07-01 18:31:25 +02:00
|
|
|
horizontal_part = im.mosaic(sec_im,
|
|
|
|
pyvips.Direction.HORIZONTAL,
|
|
|
|
marks[0][0], marks[0][1],
|
|
|
|
marks[1][0], marks[1][1])
|
2020-06-18 14:42:55 +02:00
|
|
|
|
|
|
|
if mosaiced_image is None:
|
|
|
|
mosaiced_image = horizontal_part
|
|
|
|
else:
|
|
|
|
vertical_marks = MOSAIC_VERTICAL_MARKS[i - 2:i]
|
2020-07-01 18:31:25 +02:00
|
|
|
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])
|
2020-06-18 14:42:55 +02:00
|
|
|
|
2020-07-01 18:31:25 +02:00
|
|
|
mosaiced_image = mosaiced_image.globalbalance()
|
2020-06-18 14:42:55 +02:00
|
|
|
|
|
|
|
# Uncomment to see output file
|
2020-07-01 18:31:25 +02:00
|
|
|
#mosaiced_image.write_to_file('after.jpg')
|
2020-06-18 14:42:55 +02:00
|
|
|
|
|
|
|
# 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()
|