Skip to content

Letterboxing Images and Iterating VipsImage pixel data #2260

Closed
@Transigent

Description

@Transigent

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions