You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi and sorry about the noobness of this question, I am fairly new to C and VIPS.
I am successfully using libvips in a VS2017 C++ project to load thumbnails from files on disk, using the C API. Its so FAST compared to the existing opencv implementation! Thanks for the great library.
My questions are several:
1) Existing code requires 640 x 640 thumbnails, I am currently using code like this: vips_thumbnail(FileName, &out, 640)
which gets me nearly what I need except that only the longest axis is 640, I need to supply the image data letterboxed (or pillarboxed) ie. so that it fills the whole 640 x 640 but centered and maintaining aspect ratio. I saw a weserv enhancement discussing this weserv/images#80 (comment) but I couldn't find if this has been implemented in libvips or in the thumbnailer. If not is there another fast way?
2) Theres probably an obvious answer but I could not find how to directly access the image data in the VipsImage object. The documentation description of VipsImage states that "VIPS images are three-dimensional arrays, the dimensions being width, height and bands" but I cant find examples that show how to iterate through the data, the closest I could find is a region example here which I dont know how to transmogrify so it works with an VipsImage. Is there an example of this somewhere?
3) I want to use libvips to do what an existing block of opencv code does using a cv::Mat. It iterates through the (BGR) pixel data to build a new array organized like this :
All R pixel data, followed by all G pixel data, then B pixel data.
Pixel values are changed (from uchar) to floats with values from 0 to 1
(It is formatted like this for feeding to a neural network)
At first I thought I would do the transformation manually like the original code but I have seen some really powerful code snippets like this and it occurs that libvips might already have the tools to reformat the data the way I need it. Is there any inbuilt functionality to do that?
Thanks for any advice!
The text was updated successfully, but these errors were encountered:
libvips has very efficient operation compositing -- you can run one operation after the other, and behind the scenes they join together into a fast and low-memory combined operation. So the idea behind the design of the API is that operations only implement the minimum functionality, and you get complex effects by combining primitives.
thumbnail shrinks to a bounding box. Use gravity to extend an image within a new canvas, so you need (in python, for brevity):
You can't really iterate over pixels in libvips, since images don't really exist. Everything is a delayed computation and pixels only exist on demand. You can either implement a new vips operation, or render the whole image to an area of memory and then treat it like any other array. Have a look at vips_image_write_to_memory().
You can split your image up like this (in Python, again):
# rescale to float 0 - 1
image = image / 255.0
# split bands to an array of images
bands = image.bandsplit()
# join those images vertically
image = pyvips.Image.arrayjoin(bands, across=1)
Then write to memory to make a huge float array.
You'll find python is as fast as C for libvips, so it might be more convenient.
Hi and sorry about the noobness of this question, I am fairly new to C and VIPS.
I am successfully using libvips in a VS2017 C++ project to load thumbnails from files on disk, using the C API. Its so FAST compared to the existing opencv implementation! Thanks for the great library.
My questions are several:
1) Existing code requires 640 x 640 thumbnails, I am currently using code like this:
vips_thumbnail(FileName, &out, 640)
which gets me nearly what I need except that only the longest axis is 640, I need to supply the image data letterboxed (or pillarboxed) ie. so that it fills the whole 640 x 640 but centered and maintaining aspect ratio. I saw a weserv enhancement discussing this weserv/images#80 (comment) but I couldn't find if this has been implemented in libvips or in the thumbnailer. If not is there another fast way?
2) Theres probably an obvious answer but I could not find how to directly access the image data in the VipsImage object. The documentation description of VipsImage states that "VIPS images are three-dimensional arrays, the dimensions being width, height and bands" but I cant find examples that show how to iterate through the data, the closest I could find is a region example here which I dont know how to transmogrify so it works with an VipsImage. Is there an example of this somewhere?
3) I want to use libvips to do what an existing block of opencv code does using a cv::Mat. It iterates through the (BGR) pixel data to build a new array organized like this :
(It is formatted like this for feeding to a neural network)
At first I thought I would do the transformation manually like the original code but I have seen some really powerful code snippets like this and it occurs that libvips might already have the tools to reformat the data the way I need it. Is there any inbuilt functionality to do that?
Thanks for any advice!
The text was updated successfully, but these errors were encountered: