How to use the pyvips.Image.new_from_array 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_convolution.py View on Github external
def setUp(self):
        im = pyvips.Image.mask_ideal(100, 100, 0.5, reject=True, optical=True)
        self.colour = im * [1, 2, 3] + [2, 3, 4]
        self.colour = self.colour.copy(
            interpretation=pyvips.Interpretation.SRGB)
        self.mono = self.colour.extract_band(1)
        self.mono = self.mono.copy(interpretation=pyvips.Interpretation.B_W)
        self.all_images = [self.mono, self.colour]
        self.sharp = pyvips.Image.new_from_array([[-1, -1, -1],
                                                  [-1, 16, -1],
                                                  [-1, -1, -1]], scale=8)
        self.blur = pyvips.Image.new_from_array([[1, 1, 1],
                                                 [1, 1, 1],
                                                 [1, 1, 1]], scale=9)
        self.line = pyvips.Image.new_from_array([[1, 1, 1],
                                                 [-2, -2, -2],
                                                 [1, 1, 1]])
        self.sobel = pyvips.Image.new_from_array([[1, 2, 1],
                                                  [0, 0, 0],
                                                  [-1, -2, -1]])
        self.all_masks = [self.sharp, self.blur, self.line, self.sobel]
github libvips / libvips / test / test-suite / test_convolution.py View on Github external
def setup_class(cls):
        im = pyvips.Image.mask_ideal(100, 100, 0.5, reject=True, optical=True)
        cls.colour = im * [1, 2, 3] + [2, 3, 4]
        cls.colour = cls.colour.copy(interpretation=pyvips.Interpretation.SRGB)
        cls.mono = cls.colour.extract_band(1)
        cls.mono = cls.mono.copy(interpretation=pyvips.Interpretation.B_W)
        cls.all_images = [cls.mono, cls.colour]
        cls.sharp = pyvips.Image.new_from_array([[-1, -1, -1],
                                                 [-1, 16, -1],
                                                 [-1, -1, -1]], scale=8)
        cls.blur = pyvips.Image.new_from_array([[1, 1, 1],
                                                [1, 1, 1],
                                                [1, 1, 1]], scale=9)
        cls.line = pyvips.Image.new_from_array([[1, 1, 1],
                                                [-2, -2, -2],
                                                [1, 1, 1]])
        cls.sobel = pyvips.Image.new_from_array([[1, 2, 1],
                                                 [0, 0, 0],
                                                 [-1, -2, -1]])
        cls.all_masks = [cls.sharp, cls.blur, cls.line, cls.sobel]
github libvips / libvips / test / test-suite / test_create.py View on Github external
def test_buildlut(self):
        M = pyvips.Image.new_from_array([[0, 0],
                                         [255, 100]])
        lut = M.buildlut()
        assert lut.width == 256
        assert lut.height == 1
        assert lut.bands == 1
        p = lut(0, 0)
        assert p[0] == 0.0
        p = lut(255, 0)
        assert p[0] == 100.0
        p = lut(10, 0)
        assert p[0] == 100 * 10.0 / 255.0

        M = pyvips.Image.new_from_array([[0, 0, 100],
                                         [255, 100, 0],
                                         [128, 10, 90]])
        lut = M.buildlut()
github libvips / pyvips / tests / test_create.py View on Github external
def test_buildlut(self):
        M = pyvips.Image.new_from_array([[0, 0],
                                         [255, 100]])
        lut = M.buildlut()
        assert lut.width == 256
        assert lut.height == 1
        assert lut.bands == 1
        p = lut(0, 0)
        assert p[0] == 0.0
        p = lut(255, 0)
        assert p[0] == 100.0
        p = lut(10, 0)
        assert p[0] == 100 * 10.0 / 255.0

        M = pyvips.Image.new_from_array([[0, 0, 100],
                                         [255, 100, 0],
                                         [128, 10, 90]])
        lut = M.buildlut()
        assert lut.width == 256
        assert lut.height == 1
        assert lut.bands == 2
        p = lut(0, 0)
        assert_almost_equal_objects(p, [0.0, 100.0])
        p = lut(64, 0)
        assert_almost_equal_objects(p, [5.0, 95.0])
github libvips / pyvips / tests / test_constants.py View on Github external
def test_scale_offset(self):
        im = pyvips.Image.new_from_array([1, 2], 8, 2)

        assert im.width == 2
        assert im.height == 1
        assert im.bands == 1
        assert im.scale == 8
        assert im.offset == 2
        assert im.avg() == 1.5
github libvips / pyvips / tests / perf / vips-bench.py View on Github external
def vips_bench(loops):
    range_it = range(loops)

    t0 = pyperf.perf_counter()

    for loops in range_it:
        im = pyvips.Image.new_from_file("tmp/x.tif", access='sequential')

        im = im.crop(100, 100, im.width - 200, im.height - 200)
        im = im.reduce(1.0 / 0.9, 1.0 / 0.9, kernel='linear')
        mask = pyvips.Image.new_from_array([[-1, -1, -1],
                                            [-1, 16, -1],
                                            [-1, -1, -1]], scale=8)
        im = im.conv(mask, precision='integer')

        im.write_to_file("tmp/x2.tif")

    return pyperf.perf_counter() - t0
github libvips / libvips / test / test-suite / test_convolution.py View on Github external
im = pyvips.Image.mask_ideal(100, 100, 0.5, reject=True, optical=True)
        cls.colour = im * [1, 2, 3] + [2, 3, 4]
        cls.colour = cls.colour.copy(interpretation=pyvips.Interpretation.SRGB)
        cls.mono = cls.colour.extract_band(1)
        cls.mono = cls.mono.copy(interpretation=pyvips.Interpretation.B_W)
        cls.all_images = [cls.mono, cls.colour]
        cls.sharp = pyvips.Image.new_from_array([[-1, -1, -1],
                                                 [-1, 16, -1],
                                                 [-1, -1, -1]], scale=8)
        cls.blur = pyvips.Image.new_from_array([[1, 1, 1],
                                                [1, 1, 1],
                                                [1, 1, 1]], scale=9)
        cls.line = pyvips.Image.new_from_array([[1, 1, 1],
                                                [-2, -2, -2],
                                                [1, 1, 1]])
        cls.sobel = pyvips.Image.new_from_array([[1, 2, 1],
                                                 [0, 0, 0],
                                                 [-1, -2, -1]])
        cls.all_masks = [cls.sharp, cls.blur, cls.line, cls.sobel]
github libvips / vips-bench / vips-gegl.py View on Github external
#!/usr/bin/python3

# use pyvips, but try to match the exact processing that the gegl code is
# doing, so everything is float, RGBA, and in linear light

import sys
import pyvips

im = pyvips.Image.new_from_file(sys.argv[1], access='sequential')

im = im.bandjoin(255)
im = im.colourspace('scrgb')

im = im.crop(100, 100, im.width - 200, im.height - 200)
im = im.reduce(1.0 / 0.9, 1.0 / 0.9, kernel='linear')
mask = pyvips.Image.new_from_array([[-1, -1,  -1], 
                                    [-1,  16, -1], 
                                    [-1, -1,  -1]], scale=8)
im = im.conv(mask, precision='integer')

im = im.colourspace('srgb')
im = im.extract_band(0, n=3)

im.write_to_file(sys.argv[2])
github libvips / vips-bench / vips.py View on Github external
#!/usr/bin/python3

import sys
import pyvips

im = pyvips.Image.new_from_file(sys.argv[1], access='sequential')

im = im.crop(100, 100, im.width - 200, im.height - 200)
im = im.reduce(1.0 / 0.9, 1.0 / 0.9, kernel='linear')
mask = pyvips.Image.new_from_array([[-1, -1,  -1], 
                                    [-1,  16, -1], 
                                    [-1, -1,  -1]], scale=8)
im = im.conv(mask, precision='integer')

im.write_to_file(sys.argv[2])
github libvips / pyvips / examples / try8.py View on Github external
#!/usr/bin/python

# import logging
# logging.basicConfig(level = logging.DEBUG)

import pyvips

a = pyvips.Image.new_from_array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], 8, 128)

print('scale =', a.get('scale'))
print('offset =', a.get('offset'))

a.write_to_file("x.v")