## boolean

boolean — boolean algebra on images, bitshifts

## Stability Level

Stable, unless otherwise indicated

## Synopsis

    #include <vips/vips.h>

    int                 im_andimage                         (VipsImage *in1,
                                                             VipsImage *in2,
                                                             VipsImage *out);
    int                 im_orimage                          (VipsImage *in1,
                                                             VipsImage *in2,
                                                             VipsImage *out);
    int                 im_eorimage                         (VipsImage *in1,
                                                             VipsImage *in2,
                                                             VipsImage *out);
    int                 im_andimage_vec                     (VipsImage *in,
                                                             VipsImage *out,
                                                             int n,
                                                             double *c);
    int                 im_andimageconst                    (VipsImage *in,
                                                             VipsImage *out,
                                                             double c);
    int                 im_orimage_vec                      (VipsImage *in,
                                                             VipsImage *out,
                                                             int n,
                                                             double *c);
    int                 im_orimageconst                     (VipsImage *in,
                                                             VipsImage *out,
                                                             double c);
    int                 im_eorimage_vec                     (VipsImage *in,
                                                             VipsImage *out,
                                                             int n,
                                                             double *c);
    int                 im_eorimageconst                    (VipsImage *in,
                                                             VipsImage *out,
                                                             double c);
    int                 im_shiftleft_vec                    (VipsImage *in,
                                                             VipsImage *out,
                                                             int n,
                                                             double *c);
    int                 im_shiftleft                        (VipsImage *in,
                                                             VipsImage *out,
                                                             int n);
    int                 im_shiftright_vec                   (VipsImage *in,
                                                             VipsImage *out,
                                                             int n,
                                                             double *c);
    int                 im_shiftright                       (VipsImage *in,
                                                             VipsImage *out,
                                                             int n);

## Description

These operations perform boolean operations, such as bitwise-and, on every pixel in an image or pair of images. They are useful for combining the results of the relational and morphological functions. All will work with images of any type or any mixture of types, of any size and of any number of bands.

For binary operations, if the number of bands differs, one of the images must have one band. In this case, an n-band image is formed from the one-band image by joining n copies of the one-band image together and then the two n-band images are operated upon.

In the same way, for operations that take an array constant, such as `im_andimage_vec()`, you can mix single-element arrays or single-band images freely.

If the images differ in size, the smaller image is enlarged to match the larger by adding zero pixels along the bottom and right.

The output type is the same as the input type for integer types. Float and complex types are cast to signed int.

You might think `im_andimage()` would be called "im_and", but that causes problems when we try and make a C++ binding and drop the "im_" prefix.

## Details

### im_andimage ()

    int                 im_andimage                         (VipsImage *in1,
                                                             VipsImage *in2,
                                                             VipsImage *out);

This operation calculates `in1` & `in2` and writes the result to `out`. The images may have any format. They may differ in their number of bands, see above. They may differ in size, see above.

See also: `im_orimage()`.

`in1` : | input IMAGE 1
`in2` : | input IMAGE 2
`out` : | output IMAGE
Returns : | 0 on success, -1 on error

### im_orimage ()

    int                 im_orimage                          (VipsImage *in1,
                                                             VipsImage *in2,
                                                             VipsImage *out);

This operation calculates `in1` | `in2` and writes the result to `out`. The images may have any format. They may differ in their number of bands, see above. They may differ in size, see above.

See also: `im_eorimage()`.

`in1` : | input IMAGE 1
`in2` : | input IMAGE 2
`out` : | output IMAGE
Returns : | 0 on success, -1 on error

### im_eorimage ()

    int                 im_eorimage                         (VipsImage *in1,
                                                             VipsImage *in2,
                                                             VipsImage *out);

This operation calculates `in1` ^ `in2` and writes the result to `out`. The images may have any format. They may differ in their number of bands, see above. They may differ in size, see above.

See also: `im_eorimage_vec()`, `im_andimage()`.

`in1` : | input IMAGE 1
`in2` : | input IMAGE 2
`out` : | output IMAGE
Returns : | 0 on success, -1 on error

### im_andimage_vec ()

    int                 im_andimage_vec                     (VipsImage *in,
                                                             VipsImage *out,
                                                             int n,
                                                             double *c);

This operation calculates `in` & `c` (bitwise and of image pixels with array `c`) and writes the result to `out`.

See also: `im_andimage()`, `im_orimage_vec()`.

`in` : | input IMAGE 1
`out` : | output IMAGE
`n` : | array length
`c` : | array of constants
Returns : | 0 on success, -1 on error

### im_andimageconst ()

    int                 im_andimageconst                    (VipsImage *in,
                                                             VipsImage *out,
                                                             double c);

This operation calculates `in` & `c` (bitwise and of image pixels with constant `c`) and writes the result to `out`.

See also: `im_andimage()`, `im_orimage_vec()`.

`in` : | input IMAGE 1
`out` : | output IMAGE
`c` : | constant
Returns : | 0 on success, -1 on error

### im_orimage_vec ()

    int                 im_orimage_vec                      (VipsImage *in,
                                                             VipsImage *out,
                                                             int n,
                                                             double *c);

This operation calculates `in` | `c` (bitwise or of image pixels with array `c`) and writes the result to `out`.

See also: `im_andimage()`, `im_orimageconst()`.

`in` : | input IMAGE 1
`out` : | output IMAGE
`n` : | array length
`c` : | array of constants
Returns : | 0 on success, -1 on error

### im_orimageconst ()

    int                 im_orimageconst                     (VipsImage *in,
                                                             VipsImage *out,
                                                             double c);

This operation calculates `in` | `c` (bitwise or of image pixels with constant `c`) and writes the result to `out`.

See also: `im_andimage()`, `im_orimage_vec()`.

`in` : | input IMAGE 1
`out` : | output IMAGE
`c` : | constant
Returns : | 0 on success, -1 on error

### im_eorimage_vec ()

    int                 im_eorimage_vec                     (VipsImage *in,
                                                             VipsImage *out,
                                                             int n,
                                                             double *c);

This operation calculates `in` ^ `c` (bitwise exclusive-or of image pixels with array `c`) and writes the result to `out`.

See also: `im_andimage()`, `im_orimageconst()`.

`in` : | input IMAGE 1
`out` : | output IMAGE
`n` : | array length
`c` : | array of constants
Returns : | 0 on success, -1 on error

### im_eorimageconst ()

    int                 im_eorimageconst                    (VipsImage *in,
                                                             VipsImage *out,
                                                             double c);

This operation calculates `in` ^ `c` (bitwise exclusive-or of image pixels with constant `c`) and writes the result to `out`.

See also: `im_andimage()`, `im_orimage_vec()`.

`in` : | input IMAGE 1
`out` : | output IMAGE
`c` : | constant
Returns : | 0 on success, -1 on error

### im_shiftleft_vec ()

    int                 im_shiftleft_vec                    (VipsImage *in,
                                                             VipsImage *out,
                                                             int n,
                                                             double *c);

This operation calculates `in` << `c` (left-shift by `c` bits with array `c`) and writes the result to `out`.

See also: `im_andimage()`, `im_orimageconst()`.

`in` : | input IMAGE
`out` : | output IMAGE
`n` : | array length
`c` : | array of constants
Returns : | 0 on success, -1 on error

### im_shiftleft ()

    int                 im_shiftleft                        (VipsImage *in,
                                                             VipsImage *out,
                                                             int n);

This operation calculates `in` << `n` (left-shift by `n` bits) and writes the result to `out`.

See also: `im_andimage()`, `im_orimageconst()`.

`in` : | input IMAGE
`out` : | output IMAGE
`n` : | constant
Returns : | 0 on success, -1 on error

### im_shiftright_vec ()

    int                 im_shiftright_vec                   (VipsImage *in,
                                                             VipsImage *out,
                                                             int n,
                                                             double *c);

This operation calculates `in` << `c` (right-shift by `c` bits with array `c`) and writes the result to `out`.

See also: `im_andimage()`, `im_orimageconst()`.

`in` : | input IMAGE
`out` : | output IMAGE
`n` : | array length
`c` : | array of constants
Returns : | 0 on success, -1 on error

### im_shiftright ()

    int                 im_shiftright                       (VipsImage *in,
                                                             VipsImage *out,
                                                             int n);

This operation calculates `in` >> `n` (right-shift by `n` bits) and writes the result to `out`.

See also: `im_andimage()`, `im_orimageconst()`.

`in` : | input IMAGE
`out` : | output IMAGE
`n` : | constant
Returns : | 0 on success, -1 on error

## See Also

arithmetic