The VMask class is an abstraction over the VIPS DOUBLEMASK and INTMASK types which gives convenient and safe representation of matrices.
VMask has two sub-classes, VIMask and VDMask. These represent matrices of integers and doubles respectively.
There are four constructors for VIMask and VDMask:
The first form creates an empty matrix, with the specified dimensions; the second form initialises a matrix from a varargs list; the third form sets the matrix from a vector of coefficients; the fourth from the named file. The final form makes a mask object with no contents yet.
The varargs constructors are not wrapped in Python — use the vector constructor instead. For example:
A set of member functions of VIMask provide access to the fields in the matrix:
VDMask is the same, except that the scale() and offset() members return double. VMask allows all operations that are common to VIMask and VDMask.
VMask defines copy and assignment with pointer-style semantics. You can write stuff like:
This reads the file mask, noting a pointer to the mask in fred. It then makes jim also point to it, so jim and fred are sharing the same underlying matrix values.
Internally, a VMask object is just a pointer to a reference-counting block, which in turn holds a pointer to the underlying VIPS MASK type. You can therefore efficiently pass VMask objects to functions by value, and return VMask objects as function results.
You can use [] to get at matrix elements, numbered left-to-right, top-to-bottom. Alternatively, use () to address elements by x,y position. For example:
will set the first line of the matrix to 12, and:
will set the leading diagonal to 12.
These don’t work well in Python, so there’s an extra member, get(), which will get an element by x,y position.
See the member functions below for other operations on VMask.
The following operations are defined for VIMask:
The following operations are defined for VDMask:
You can output masks with the usual << operator.