pyvips | python binding for libvips using cffi | Computer Vision library
kandi X-RAY | pyvips Summary
kandi X-RAY | pyvips Summary
python binding for libvips using cffi
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- 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
pyvips Key Features
pyvips Examples and Code Snippets
$ ~/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
thumb = pyvips.Image.thumbnail("some-file.jpg", 128)
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)
import pyvips
image = pyvips.Image.new_from_file("img.svg", dpi=300)
image.write_to_file("img.png")
$ 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
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)
$ 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
#!/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):
#
#!/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
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
Trending Discussions on pyvips
QUESTION
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:29I 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:
QUESTION
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:12The thumbnail operation in pyvips will resize to fit an area. For example:
QUESTION
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:49It worked for me finally by avoiding the auxiliary variables.
QUESTION
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:10Try turning off filtering:
QUESTION
Here's a (theoretically) simple task I have at hand:
- Load transparent animated GIF from disk (or buffer)
- Convert all individual frames into NumPy arrays. Each frame WITH ALPHA CHANNEL
- 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:57I 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:
QUESTION
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:30pyvips 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:
QUESTION
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:50By 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:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pyvips
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
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page