Next: 3.6 Writing results Up: 3. The VImage class Previous: 3.4 Assignment Contents

#
3.5 Computing with `VImage`s

All VIPS image processing operations are member functions of the `VImage` class. For example:

    VImage fred( "fred.v" );
    VImage jim( "jim.v" );

    Vimage result = fred.cos() + jim;

Will apply `im_costra()` to `fred.v`, making an image where each pixel is the cosine of the corresponding pixel in `fred.v`; then add that image to `jim.v`. Finally, the result will be held in `result`.

VIPS is a demand-driven image processing system: when it computes expressions like this, no actual pixels are calculated (although you can use the projection functions on images -- `result.BandFmt()` for example). When you finally write the result to a file (or use some operation that needs pixel values, such as `min()`, find minimum value), VIPS evaluates all of the operations you have called to that point in parallel. If you have more than one CPU in your machine, the load is spread over the available processors. This means that there is no limit to the size of the images you can process.

Section 4 lists all of the members, but these general rules apply:

- VIPS operation names become C++ member function names by dropping the `im_` prefix, and if present, the `tra` postfix. For example, the VIPS operation `im_extract()` becomes `extract()`, and `im_costra()` becomes `cos()`.

- The `VImage` object to which you apply the member function is the first input image, the member function returns the first output. If there is no image input, the member is declared `static`.

- `INTMASK` and `DOUBLEMASK` types become `VMask` objects, `im_col_display` types become `VDisplay` objects.

This part of the C++ API is generated automatically from the VIPS function database, so it should all be up-to-date.

There are a set of arithmetic operators defined for your convenience:

    VImage operator+( VImage a, VImage b );
    VImage operator+( double a, VImage b );
    VImage operator+( VImage a, double b );
    VImage operator-( VImage a, VImage b );
    VImage operator-( double a, VImage b );
    VImage operator-( VImage a, double b );
    VImage operator*( VImage a, VImage b );
    VImage operator*( double a, VImage b );
    VImage operator*( VImage a, double b );
    VImage operator/( VImage a, VImage b );
    VImage operator/( double a, VImage b );
    VImage operator/( VImage a, double b );
    VImage operator-( VImage a );
    VImage operator%( VImage a, VImage b );
    VImage operator%( VImage a, double b );
    VImage operator<( VImage a, VImage b );
    VImage operator<( double a, VImage b );
    VImage operator<( VImage a, double b );
    VImage operator<=( VImage a, VImage b );
    VImage operator<=( double a, VImage b );
    VImage operator<=( VImage a, double b );
    VImage operator>( VImage a, VImage b );
    VImage operator>( double a, VImage b );
    VImage operator>( VImage a, double b );
    VImage operator>=( VImage a, VImage b );
    VImage operator>=( double a, VImage b );
    VImage operator>=( VImage a, double b );
    VImage operator==( VImage a, VImage b );
    VImage operator==( double a, VImage b );
    VImage operator==( VImage a, double b );
    VImage operator!=( VImage a, VImage b );
    VImage operator!=( double a, VImage b );
    VImage operator!=( VImage a, double b );
    VImage operator&( VImage a, VImage b );
    VImage operator&( double a, VImage b );
    VImage operator&( VImage a, double b );
    VImage operator|( VImage a, VImage b );
    VImage operator|( double a, VImage b );
    VImage operator|( VImage a, double b );
    VImage operator^( VImage a, VImage b );
    VImage operator^( double a, VImage b );
    VImage operator^( VImage a, double b );
    VImage operator<<( VImage a, int b );
    VImage operator>>( VImage a, int b );
    VImage operator-( VImage a );

So you can write stuff like:

    VImage fred( "fred.v" );
    VImage jim( "jim.v" );

    Vimage result = (fred + jim) / 2;

Next: 3.6 Writing results Up: 3. The VImage class Previous: 3.4 Assignment Contents