pyvips | python binding for libvips using cffi | Computer Vision library

 by   libvips Python Version: 2.2.3 License: MIT

kandi X-RAY | pyvips Summary

kandi X-RAY | pyvips Summary

pyvips is a Python library typically used in Artificial Intelligence, Computer Vision, OpenCV applications. pyvips has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has low support. You can install using 'pip install pyvips' or download it from GitHub, PyPI.

python binding for libvips using cffi
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              pyvips has a low active ecosystem.
              It has 510 star(s) with 48 fork(s). There are 8 watchers for this library.
              There were 2 major release(s) in the last 12 months.
              There are 138 open issues and 216 have been closed. On average issues are closed in 63 days. There are 1 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of pyvips is 2.2.3

            kandi-Quality Quality

              pyvips has 0 bugs and 0 code smells.

            kandi-Security Security

              pyvips has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              pyvips code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              pyvips is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              pyvips releases are not available. You will need to build from source code and install.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              pyvips saves you 1634 person hours of effort in developing the same functionality from scratch.
              It has 4230 lines of code, 350 functions and 64 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed pyvips and discovered the below as its top functions. This is intended to give you an instant insight into pyvips implemented functionality, and help decide if they suit your requirements.
            • Generate documentation for pyvips
            • Gets a type from a name
            • Find the name of a nickname
            • Convert x to a string
            • Create a Vips operation
            • Return an Introspect instance for the given operation
            • Convert x to bytes
            • Set string options
            • Set the object
            • Create a pointer to a gtype
            • Fetch a region from the region
            • Return a list of all libvips
            • Calculate the average average value of an image
            • Generate a typedefs
            • Create a new source from a file
            • Get a GObject property
            • Convert an image to rectangular coordinates
            • Setup library
            • Register a callback for reading data
            • Convert gtype to python type
            • Setup libvips
            • Create a new interpolator
            • Generate a docstring for an operation
            • Create a TargetCustom
            • Generate GEnums
            • Compute shepards on a given image
            Get all kandi verified functions for this library.

            pyvips Key Features

            No Key Features are available at this moment for pyvips.

            pyvips Examples and Code Snippets

            Strange behavior in pyvips, impossible to write some images
            Pythondot img1Lines of Code : 7dot img1License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            $ ~/w32/vips-dev-8.12/bin/vips.exe copy MapFishermansRowHexBigBig.png x2.png
            pngload: arithmetic overflow
            vips2png: unable to write to target x2.png
            
            $ ~/vips-dev-8.12/bin/vips.exe copy MapFishermansRowHexBigBig.png
            Resize to Specific Height and Width with pyvips
            Pythondot img2Lines of Code : 2dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            thumb = pyvips.Image.thumbnail("some-file.jpg", 128)
            
            How to assign image components in pyvips?
            Pythondot img3Lines of Code : 4dot img3License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            image = pyvips.Image.new_from_file('image.jpg', access='sequential')
            image_hsv= image.colourspace("hsv")
            image_hsv[0].hist_local(40, 40, max_slope=5)
            
            Convert a SVG to PNG using python?
            Pythondot img4Lines of Code : 5dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import pyvips
            
            image = pyvips.Image.new_from_file("img.svg", dpi=300)
            image.write_to_file("img.png")
            
            Reducing PNG file size with pyvips: matching ImgBot and ImageMagick optimizations
            Pythondot img5Lines of Code : 4dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            $ vips copy giant.png x.png[palette,compression=9,strip,filter=0]
            $ ls -l x.png
            -rw-r--r-- 1 john john 41147 Feb 14 10:58 x.png
            
            How to merge tiles obtained using openslide-python
            Pythondot img6Lines of Code : 12dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import pyvips
            
            image = pyvips.Image.new_from_file("my-slide.svs")
            image.dzsave("my-deepzoom")
            
            import pyvips
            
            tiles = [pyvips.Image.new_from_file(f"{x}_{y}.jpeg", access="sequential")
                     for y in range(height)
            libvips / pyvips access small sections of a multi-channel tiff (OME-Tiff)
            Pythondot img7Lines of Code : 39dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            $ vipsheader -a multi-channel-z-series.ome.tif 
            multi-channel-z-series.ome.tif: 439x167 char, 1 band, b-w, tiffload
            width: 439
            height: 167
            bands: 1
            format: char
            coding: none
            interpretation: b-w
            xoffset: 0
            yoffset: 0
            xres: 0
            yres: 0
            filenam
            Python Pillow Image combination
            Pythondot img8Lines of Code : 98dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            #!/usr/bin/python3
            
            import sys
            import math
            import pyvips
            
            column_width = 256
            row_height = 256
            background_colour = 255 # you could use eg. [128, 255, 128] as well
            
            # pop enough tiles from the argument to fill a page
            def layout(tiles):
                #
            Generate image file without keeping the whole image in memory
            Pythondot img9Lines of Code : 25dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            #!/usr/bin/python3
            
            import sys
            import pyvips
            
            # make a huge two-band image where each pixel has the value of its (x, y)
            # coordinate
            xy = pyvips.Image.xyz(16384, 16384)
            
            # subtract the half way point, so each pixel is now -8192 to +8191
            xy
            opencv python reading image as RGB
            Pythondot img10Lines of Code : 16dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            RGBimage = BGRimage[...,::-1]
            
            BGRimage = RGBimage[...,::-1]
            
            RGBimage = cv2.cvtColor(BGRimage, cv2.COLOR_BGR2RGB)
            
            # Load image with OpenCV and process in BGR order
            i

            Community Discussions

            QUESTION

            Strange behavior in pyvips, impossible to write some images
            Asked 2022-Jan-23 at 12:29

            I'm currently trying to make pyvips work for a project where I need to manipulate images of a "big but still sensible" size, between 1920x1080 and 40000x40000.

            The installation worked well, but these particular 2 lines sometime work, sometime don't.

            ...

            ANSWER

            Answered 2022-Jan-23 at 12:29

            I found your error message in libspng:

            https://github.com/randy408/libspng/blob/master/spng/spng.c#L5989

            It looks like it's being triggered if the decompressed image size would go over your process pointer size. If I try a 32-bit libvips on Windows I see:

            Source https://stackoverflow.com/questions/70818038

            QUESTION

            Resize to Specific Height and Width with pyvips
            Asked 2021-Sep-28 at 14:12

            I find this answer, and I want to use pyvips to resize images. In the mentioned answer and the official documentation image resized by scale. However, I want to resize the image to a specific height and width. Is there any way to achieve this with pyvips?

            ...

            ANSWER

            Answered 2021-Sep-28 at 14:12

            The thumbnail operation in pyvips will resize to fit an area. For example:

            Source https://stackoverflow.com/questions/69363178

            QUESTION

            How to assign image components in pyvips?
            Asked 2021-May-31 at 08:49

            I am using the pyvips library which has a special object for images, these objects have the 3 bands corresponding to HSV (or other) colour space components. The problem is that, after filtering one of the HSV components, it is not allowed to assign it again to the ogirinal image. On this code you can see what is written and the error.

            ...

            ANSWER

            Answered 2021-May-31 at 08:49

            It worked for me finally by avoiding the auxiliary variables.

            Source https://stackoverflow.com/questions/67770255

            QUESTION

            Reducing PNG file size with pyvips: matching ImgBot and ImageMagick optimizations
            Asked 2021-Feb-14 at 11:10

            I'm trying to minimize file size of PNG images written with pyvips.Image.pngsave(). Original files written with just .pngsave(output) are at https://github.com/CDDA-Tilesets/UltimateCataclysm and we'll look at giant.png which is 119536 bytes.

            ImgBot was able to reduce file size to 50672.

            pngsave(output, compression=9, palette=True, strip=True) to 58722

            But the convert command from ImageMagick is still able to reduce file size further after the latter, to 42833 with default options:

            ...

            ANSWER

            Answered 2021-Feb-14 at 11:10

            Try turning off filtering:

            Source https://stackoverflow.com/questions/66183080

            QUESTION

            How to read and write animated GIF with transparency
            Asked 2020-Dec-18 at 22:18

            Here's a (theoretically) simple task I have at hand:

            1. Load transparent animated GIF from disk (or buffer)
            2. Convert all individual frames into NumPy arrays. Each frame WITH ALPHA CHANNEL
            3. Save NumPy arrays back into transparent animated GIF

            Output file size is irrelevant, all I really need is to have are two identical GIFs - the original input image and the one saved in step 3.

            What does matter to me though it de/encoding speed so pure Python solutions (without C bindings to the underlying imaging library) are not considered.

            Attached (at the very bottom), you will find an example GIF I am using for testing.

            I tried pretty much every single approach that comes to mind. Either the resulting GIF (step 3) is terribly butchered, rendered in grayscale only, or (at best), looses transparency and is saved on either white or black background.

            Here's what I tried:

            Read with Pillow:

            ...

            ANSWER

            Answered 2020-Dec-18 at 15:57

            I believe you're encountering an issue because you're not saving the palette associated with each frame. When you convert each frame to an array, the resulting array doesn't contain any of the palette data which specifies what colours are included in the frame. So, when you construct a new image from each frame, the palette is not present, and Pillow doesn't know what colour palette it should use for the frame.

            Also, when saving the GIF, you need to specify the colour to use for transparency, which we can just extract from the original image.

            Here's some code which (hopefully) produces the result you want:

            Source https://stackoverflow.com/questions/65357342

            QUESTION

            libvips / pyvips access small sections of a multi-channel tiff (OME-Tiff)
            Asked 2020-Oct-22 at 17:30

            Wondering if there's a speedy way to return specific pixel ranges of a given channel of an ome-tiff file using pyvips / libvips. The crop doesn't allow for channel specfics.

            My OME-Tiff is large (10 GB+) so I don't want to load the entire image into memory.

            Open to any suggestions and/or other workflows.

            ...

            ANSWER

            Answered 2020-Oct-22 at 17:30

            pyvips supports multipage documents as "toilet-roll" images (sorry). You set n=-1 to load all the pages, and they appear as a very tall, thin image, with the pages stacked vertically. The metadata item page-height gives the height in pixels of each sheet.

            Docs here:

            https://libvips.github.io/libvips/API/current/VipsForeignSave.html#vips-tiffload

            For example:

            Source https://stackoverflow.com/questions/64486798

            QUESTION

            libvips Nearest Neighbor / Bicubic Deep Zoom Pyramid Creation
            Asked 2020-Jan-31 at 08:50

            I'm in the process of moving some of my code off of openzoom.py and onto Libvips but am not sure how dictate the interpolation method, which is important. I at the very least need to be able to use bicubic/bilinear in one case and nearest neighbors in the other case.

            My old code is as follows:

            ...

            ANSWER

            Answered 2020-Jan-31 at 08:50

            By default, dzsave will average each 2x2 block of pixels, which is equivalent to bilinear.

            Sometimes, for example with images where pixel values represent labels rather than intensity, you need a non-interpolatory downsize. For these cases, you can use the region_shrink parameter to select median or mode, which will both preserve label values.

            I would use:

            Source https://stackoverflow.com/questions/59971673

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install pyvips

            You can install using 'pip install pyvips' or download it from GitHub, PyPI.
            You can use pyvips like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • PyPI

            pip install pyvips

          • CLONE
          • HTTPS

            https://github.com/libvips/pyvips.git

          • CLI

            gh repo clone libvips/pyvips

          • sshUrl

            git@github.com:libvips/pyvips.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link