How to use the pyvips.Image 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 / libvips / test / test-suite / test_convolution.py View on Github external
def test_gaussblur(self):
        for im in self.all_images:
            for prec in [pyvips.Precision.INTEGER, pyvips.Precision.FLOAT]:
                for i in range(5, 10):
                    sigma = i / 5.0
                    gmask = pyvips.Image.gaussmat(sigma, 0.2,
                                                  precision=prec)

                    a = im.conv(gmask, precision=prec)
                    b = im.gaussblur(sigma, min_ampl=0.2, precision=prec)

                    a_point = a(25, 50)
                    b_point = b(25, 50)

                    assert_almost_equal_objects(a_point, b_point,
                                                threshold=0.1)
github libvips / libvips / test / test-suite / test_conversion.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]).copy(interpretation="srgb")
        cls.mono = cls.colour[1].copy(interpretation="b-w")
        cls.all_images = [cls.mono, cls.colour]
        cls.image = pyvips.Image.jpegload(JPEG_FILE)
github libvips / libvips / test / test-suite / helpers / helpers.py View on Github external
def run_fn2(fn, x, y):
    if isinstance(x, pyvips.Image) or isinstance(y, pyvips.Image):
        return fn(x, y)
    elif isinstance(x, list) or isinstance(y, list):
        return [fn(i, j) for i, j in zip_expand(x, y)]
    else:
        return fn(x, y)
github libvips / pyvips / tests / test_iofuncs.py View on Github external
def test_new_from_memory(self):
        s = bytearray(200)
        im = pyvips.Image.new_from_memory(s, 20, 10, 1, 'uchar')

        assert im.width == 20
        assert im.height == 10
        assert im.format == 'uchar'
        assert im.bands == 1
        assert im.avg() == 0

        im += 10

        assert im.avg() == 10
github libvips / pyvips / examples / try14.py View on Github external
#!/usr/bin/python

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

import pyvips

a = pyvips.Image.black(100, 100)
b = a.bandjoin(2)

b.write_to_file("x.v")

txt = pyvips.Image.text("left corner", dpi=300)

c = txt.ifthenelse(2, [0, 255, 0], blend=True)

c.write_to_file("x2.v")
github libvips / pyvips / pyvips / vimage.py View on Github external
def __div__(self, other):
        if isinstance(other, pyvips.Image):
            return self.divide(other)
        else:
            return self.linear(_smap(lambda x: 1.0 / x, other), 0)
github MEDAL-IITB / Fast_WSI_Color_Norm / Run_ColorNorm.py View on Github external
def numpy2vips(a):
    height, width, bands = a.shape
    linear = a.reshape(width * height * bands)
    vi = pyvips.Image.new_from_memory(linear.data, width, height, bands,
                                      dtype_to_format[str(a.dtype)])
    return vi
################################
github ecometrica / gdal2mbtiles / gdal2mbtiles / vips.py View on Github external
def write_buffer(self, image, resolution):
        if VImageAdapter(image).BufferSize() >= self.IMAGE_BUFFER_DISK_THRESHOLD:
            logger.debug(
                'Buffering resolution {0} to disk'.format(resolution)
            )
            vipsfile = Image.new_temp_file("%s.v")
            tempfile_image = image.write(vipsfile)
            return tempfile_image

        logger.debug(
            'Buffering resolution {0} to memory'.format(resolution)
        )
        return Image.new_from_memory(
            image.write_to_memory(), image.width, image.height, image.bands,
            'uchar'
        )
github comic / grand-challenge.org / app / grandchallenge / cases / image_builders / tiff.py View on Github external
def create_dzi_images(*, tiff_file: GrandChallengeTiffFile, pk) -> str:
    # Creates a dzi file(out.dzi) and corresponding tiles in folder {pk}_files
    dzi_output = str(tiff_file.path.parent / str(pk))
    try:
        image = pyvips.Image.new_from_file(
            str(tiff_file.path.absolute()), access="sequential"
        )

        pyvips.Image.dzsave(
            image, dzi_output, tile_size=settings.DZI_TILE_SIZE
        )
    except Exception as e:
        raise ValidationError("Image can't be converted to dzi: " + str(e))

    return dzi_output
github libvips / pyvips / examples / try3.py View on Github external
#!/usr/bin/python

import sys

import pyvips

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

pyvips.cache_set_trace(True)

a = pyvips.Image.new_from_file(sys.argv[1])
print(a.max())
print(a.max())