Comments (6)
Hi again, do you mind if I close this issue? It's confusing having two open for almost the same thing. Let's continue discussion in the other one.
from pyvips.
Hello, unfortunately libvips does not support read and write from pipes. You need to write to a memory buffer, then write that to stdout.
The fastest way is as a simple C-style memory array. There's an example here of passing an image between vips, numpy and PIL:
https://github.com/jcupitt/pyvips/blob/master/examples/pil-numpy-pyvips.py
Does ffmpeg support piping uncompressed areas of memory like that? If not, I guess you'll want the image coded as a jpg. You can use write_to_buffer
to make a string containing a jpg-coded image:
https://jcupitt.github.io/pyvips/vimage.html#pyvips.Image.write_to_buffer
from pyvips.
Thanks John, I was able to get it to work using PIL as the mechanism to write to std.in, I just had to read your jpeg buffer as bytes. See below:
image_vips = image_offset.smartcrop(self.output_raster_width, self.output_raster_height)
data = image_vips.write_to_buffer('.JPEG', Q=95)
image_bytes = PIL.Image.open(io.BytesIO(data))
image_bytes.save(p.stdin, 'JPEG')
I tested the script you provided. Fast indeed! So this begs the question (forgive me if it's a silly question), for anything Vips does at speed is it just using np under the hood? The reason I ask is, I benchmarked both Pillow and Vips doing the same operations of resize, offset, crop, and I actually found Vips to be much slower. The vips code I used is roughly as follows:
self.original_image = pyvips.Image.new_from_file(self.file_path)
self.original_image_width = self.original_image.width
self.original_image_height = self.original_image.height
for frame in range(100):
image_resize = self.original_image.resize(zoom)
image_offset = image_resize.copy(xoffset = int(x_total), yoffset = int(y_total))
image_vips = image_offset.smartcrop(self.output_raster_width, self.output_raster_height)
data = image_vips.write_to_buffer('.JPEG', Q=95)
image_bytes = PIL.Image.open(io.BytesIO(data))
image_bytes.save(p.stdin, 'JPEG')
Is it slow because it's reading from disk every time (It shouldn't be though, since the object is established at the beginning)? Are the cffi mappings not actually in-play when not utilizing the numpy arrays?
from pyvips.
smartcrop
is very slow. Try just crop(left, top, width, height)
.
from pyvips.
libvips has its own pixel functions, it doesn't use numpy.
You have:
image_vips = image_offset.smartcrop(self.output_raster_width, self.output_raster_height)
data = image_vips.write_to_buffer('.JPEG', Q=95)
image_bytes = PIL.Image.open(io.BytesIO(data))
image_bytes.save(p.stdin, 'JPEG')
You're encoding jpg twice there, there's no need. Just do something like:
image_vips = image_offset.smartcrop(self.output_raster_width, self.output_raster_height)
data = image_vips.write_to_buffer('.JPEG', Q=95)
sys.stdout.write(data)
from pyvips.
Hey John, just played off this in the other thread :-)
from pyvips.
Related Issues (20)
- Does Pyvips have uniformly sampled noise? HOT 2
- Select interpretation when initializing the image HOT 1
- VipsOperation: class "pdfload" not found HOT 2
- SVG rendering failed HOT 1
- JPEG compression resulted in color error. HOT 1
- How to generate patches from coordinate list by a multiprocessing way? HOT 1
- Dtype auto conversion while running script HOT 6
- new release when & ship with libvips? HOT 14
- ICC Profile Application on SVS and tiffsave hangs randomly
- High RAM usage with fetch when reading multiple WSI tiles HOT 2
- Slower first run, even without cache HOT 2
- using resource.setrlimit makes pyvips / liborc spit the dummy HOT 2
- Memory leaking with pdf HOT 21
- dzsave_target returns NoneType not list[] as in docs HOT 1
- Pyvips fetch returns bad image on .svs files HOT 4
- Reading in image a second time breaks on qptiff file HOT 6
- Documentation link to conda package HOT 1
- Create svs file with image pyramid, label and macro in pyvips? HOT 4
- Image merge stitch HOT 2
- `addalpha` has different behaviour compared to C HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyvips.