How to use the pyvips.Image.black function in pyvips

To help you get started, we’ve selected a few pyvips examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github libvips / pyvips / tests / test_constants.py View on Github external
def test_array_const_args(self):
        r = pyvips.Image.black(16, 16)
        r = r.draw_rect(255, 10, 12, 1, 1)
        g = pyvips.Image.black(16, 16)
        g = g.draw_rect(255, 10, 11, 1, 1)
        b = pyvips.Image.black(16, 16)
        b = b.draw_rect(255, 10, 10, 1, 1)
        im = r.bandjoin([g, b])

        assert im.width == 16
        assert im.height == 16
        assert im.bands == 3

        im = im.conv([
            [0.11, 0.11, 0.11],
            [0.11, 0.11, 0.11],
            [0.11, 0.11, 0.11]
        ])

        assert im.width == 16
        assert im.height == 16
        assert im.bands == 3
github libvips / libvips / test / test-suite / test_arithmetic.py View on Github external
def test_find_trim(self):
        if pyvips.type_find("VipsOperation", "find_trim") != 0:
            im = pyvips.Image.black(50, 60) + 100
            test = im.embed(10, 20, 200, 300, extend="white")

            for x in unsigned_formats + float_formats:
                a = test.cast(x)
                left, top, width, height = a.find_trim()

                assert left == 10
                assert top == 20
                assert width == 50
                assert height == 60

            test_rgb = test.bandjoin([test, test])
            left, top, width, height = test_rgb.find_trim(background=[255, 255,
                                                                      255])
            assert left == 10
            assert top == 20
github libvips / pyvips / tests / test_iofuncs.py View on Github external
def test_get_fields(self):
        im = pyvips.Image.black(10, 10)
        fields = im.get_fields()
        # we might add more fields later
        assert len(fields) > 10
        assert fields[0] == 'width'
github libvips / pyvips / tests / test_conversion.py View on Github external
def test_gravity(self):
        im = pyvips.Image.black(1, 1) + 255

        positions = [
            ['centre', 1, 1],
            ['north', 1, 0],
            ['south', 1, 2],
            ['east', 2, 1],
            ['west', 0, 1],
            ['north-east', 2, 0],
            ['south-east', 2, 2],
            ['south-west', 0, 2],
            ['north-west', 0, 0]
        ]

        for direction, x, y in positions:
            im2 = im.gravity(direction, 3, 3)
            assert_almost_equal_objects(im2(x, y), [255])
github libvips / pyvips / tests / test_draw.py View on Github external
def test_draw_circle(self):
        im = pyvips.Image.black(100, 100)
        im = im.draw_circle(100, 50, 50, 25)
        pixel = im(25, 50)
        assert len(pixel) == 1
        assert pixel[0] == 100
        pixel = im(26, 50)
        assert len(pixel) == 1
        assert pixel[0] == 0

        im = pyvips.Image.black(100, 100)
        im = im.draw_circle(100, 50, 50, 25, fill=True)
        pixel = im(25, 50)
        assert len(pixel) == 1
        assert pixel[0] == 100
        pixel = im(26, 50)
        assert pixel[0] == 100
        pixel = im(24, 50)
        assert pixel[0] == 0
github libvips / pyvips / tests / test_colour.py View on Github external
def test_colourspace(self):
        # mid-grey in Lab ... put 42 in the extra band, it should be copied
        # unmodified
        test = pyvips.Image.black(100, 100) + [50, 0, 0, 42]
        test = test.copy(interpretation=pyvips.Interpretation.LAB)

        # a long series should come in a circle
        im = test
        for col in colour_colourspaces + [pyvips.Interpretation.LAB]:
            im = im.colourspace(col)
            self.assertEqual(im.interpretation, col)

            for i in range(0, 4):
                min_l = im.extract_band(i).min()
                max_h = im.extract_band(i).max()
                self.assertAlmostEqual(min_l, max_h)

            pixel = im(10, 10)
            self.assertAlmostEqual(pixel[3], 42, places=2)
github libvips / libvips / test / test-suite / test_arithmetic.py View on Github external
def test_hough_circle(self):
        test = pyvips.Image.black(100, 100).draw_circle(100, 50, 50, 40)

        for fmt in all_formats:
            im = test.cast(fmt)
            hough = im.hough_circle(min_radius=35, max_radius=45)

            v, x, y = hough.maxpos()
            vec = hough(x, y)
            r = vec.index(v) + 35

            assert pytest.approx(x) == 50
            assert pytest.approx(y) == 50
            assert pytest.approx(r) == 40
github libvips / pyvips / tests / test_arithmetic.py View on Github external
def test_measure(self):
        im = pyvips.Image.black(50, 50)
        test = im.insert(im + 10, 50, 0, expand=True)

        for x in noncomplex_formats:
            a = test.cast(x)
            matrix = a.measure(2, 1)
            [p1] = matrix(0, 0)
            [p2] = matrix(0, 1)

            assert pytest.approx(p1) == 0
            assert pytest.approx(p2) == 10
github libvips / pyvips / tests / test_arithmetic.py View on Github external
def test_min(self):
        test = (pyvips.Image.black(100, 100) + 100).draw_rect(0, 40, 50, 1, 1)

        for fmt in all_formats:
            v = test.cast(fmt).min()

            assert pytest.approx(v) == 0
            v, x, y = test.cast(fmt).minpos()
            assert pytest.approx(v) == 0
            assert pytest.approx(x) == 40
            assert pytest.approx(y) == 50
github libvips / pyvips / tests / test_arithmetic.py View on Github external
def test_find_trim(self):
        if pyvips.type_find("VipsOperation", "find_trim") != 0:
            im = pyvips.Image.black(50, 60) + 100
            test = im.embed(10, 20, 200, 300, extend="white")

            for x in unsigned_formats + float_formats:
                a = test.cast(x)
                left, top, width, height = a.find_trim()

                assert left == 10
                assert top == 20
                assert width == 50
                assert height == 60

            test_rgb = test.bandjoin([test, test])
            left, top, width, height = test_rgb.find_trim(background=[255, 255,
                                                                      255])
            assert left == 10
            assert top == 20