File: test_morphology.py

package info (click to toggle)
vips 8.18.0-2
  • links: PTS
  • area: main
  • in suites: forky
  • size: 53,448 kB
  • sloc: ansic: 172,621; cpp: 12,257; python: 5,077; sh: 773; perl: 40; makefile: 25; javascript: 6
file content (55 lines) | stat: -rw-r--r-- 1,698 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# vim: set fileencoding=utf-8 :
import pytest

import pyvips


class TestMorphology:
    def test_countlines(self):
        im = pyvips.Image.black(100, 100)
        im = im.draw_line(255, 0, 50, 100, 50)
        n_lines = im.countlines(pyvips.Direction.HORIZONTAL)
        assert n_lines == 1

    def test_labelregions(self):
        im = pyvips.Image.black(100, 100)
        im = im.draw_circle(255, 50, 50, 25, fill=True)
        mask, opts = im.labelregions(segments=True)

        assert opts['segments'] == 3
        assert mask.max() == 2

    def test_erode(self):
        im = pyvips.Image.black(100, 100)
        im = im.draw_circle(255, 50, 50, 25, fill=True)
        im2 = im.erode([[128, 255, 128],
                        [255, 255, 255],
                        [128, 255, 128]])
        assert im.width == im2.width
        assert im.height == im2.height
        assert im.bands == im2.bands
        assert im.avg() > im2.avg()

    def test_dilate(self):
        im = pyvips.Image.black(100, 100)
        im = im.draw_circle(255, 50, 50, 25, fill=True)
        im2 = im.dilate([[128, 255, 128],
                         [255, 255, 255],
                         [128, 255, 128]])
        assert im.width == im2.width
        assert im.height == im2.height
        assert im.bands == im2.bands
        assert im2.avg() > im.avg()

    def test_rank(self):
        im = pyvips.Image.black(100, 100)
        im = im.draw_circle(255, 50, 50, 25, fill=True)
        im2 = im.rank(3, 3, 8)
        assert im.width == im2.width
        assert im.height == im2.height
        assert im.bands == im2.bands
        assert im2.avg() > im.avg()


if __name__ == '__main__':
    pytest.main()