API reference - Class Image

Notation used in Ruby API documentation

Description: An image to be stored as a layout annotation

Images can be put onto the layout canvas as annotations, along with rulers and markers. Images can be monochrome (represent scalar data) as well as color (represent color images). The display of images can be adjusted in various ways, i.e. color mapping (translation of scalar values to colors), geometrical transformations (including rotation by arbitrary angles) and similar. Images are always based on floating point data. The actual data range is not fixed and can be adjusted to the data set (i.e. 0..255 or -1..1). This gives a great flexibility when displaying data which is the result of some measurement or calculation for example. The basic parameters of an image are the width and height of the data set, the width and height of one pixel, the geometrical transformation to be applied, the data range (min_value to max_value) and the data mapping which is described by an own class, ImageDataMapping.

Starting with version 0.22, the basic transformation is a 3x3 matrix rather than the simple affine transformation. This matrix includes the pixel dimensions as well. One consequence of that is that the magnification part of the matrix and the pixel dimensions are no longer separated. That has certain consequences, i.e. setting an affine transformation with a magnification scales the pixel sizes as before but an affine transformation returned will no longer contain the pixel dimensions as magnification because it only supports isotropic scaling. For backward compatibility, the rotation center for the affine transformations while the default center and the center for matrix transformations is the image center.

Public constructors

new Image ptrnewCreate a new image with the default attributes
new Image ptrnew(string filename)Constructor from a image file
new Image ptrnew(string filename,
const DCplxTrans trans)
Constructor from a image file
new Image ptrnew(unsigned long w,
unsigned long h,
double[] data)
Constructor for a monochrome image with the given pixel values
new Image ptrnew(unsigned long w,
unsigned long h,
const DCplxTrans trans,
double[] data)
Constructor for a monochrome image with the given pixel values
new Image ptrnew(unsigned long w,
unsigned long h,
double[] red,
double[] green,
double[] blue)
Constructor for a color image with the given pixel values
new Image ptrnew(unsigned long w,
unsigned long h,
const DCplxTrans trans,
double[] red,
double[] green,
double[] blue)
Constructor for a color image with the given pixel values

Public methods

void_createEnsures the C++ object is created
void_destroyExplicitly destroys the object
[const]bool_destroyed?Returns a value indicating whether the object was already destroyed
[const]bool_is_const_object?Returns a value indicating whether the reference is a const reference
void_manageMarks the object as managed by the script side.
void_unmanageMarks the object as no longer owned by the script side.
voidassign(const Image other)Assigns another object to self
[const]DBoxboxGet the bounding box of the image
[const]ImageDataMappingdata_mappingGet the data mapping
voiddata_mapping=(const ImageDataMapping data_mapping)Set the data mapping object
[const]new Image ptrdupCreates a copy of self
[const]stringfilenameGet the name of the file loaded of an empty string if not file is loaded
[const]doubleget_pixel(unsigned long x,
unsigned long y)
Accessor to one pixel (monochrome and color)
[const]doubleget_pixel(unsigned long x,
unsigned long y,
unsigned int component)
Accessor to one pixel (monochrome and color)
[const]unsigned longheightGet the height of the image in pixels
[const]intidGet the Id
[const]boolis_color?Returns true, if the image is a color image
[const]boolis_empty?Returns true, if the image does not contain any data (i.e. is default constructed)
[const]boolis_visible?Gets a flag indicating whether the image object is visible
[const]boolmask(unsigned long x,
unsigned long y)
Gets the mask for one pixel
[const]Matrix3dmatrixReturn the pixel-to-micron transformation matrix
voidmatrix=(const Matrix3d t)Set the transformation matrix
[const]doublemax_valueSet the maximum value
voidmax_value=(double v)Get the upper limit of the values in the data set
[const]doublemin_valueGet the upper limit of the values in the data set
voidmin_value=(double v)Set the minimum value
[const]doublepixel_heightGet the pixel height
voidpixel_height=(double h)Set the pixel height
[const]doublepixel_widthGet the pixel width
voidpixel_width=(double w)Set the pixel width
voidset_data(unsigned long w,
unsigned long h,
double[] d)
Write the image data field (monochrome)
voidset_data(unsigned long w,
unsigned long h,
double[] r,
double[] g,
double[] b)
Write the image data field (color)
voidset_mask(unsigned long x,
unsigned long y,
bool m)
Set the mask for a pixel
voidset_pixel(unsigned long x,
unsigned long y,
double v)
Set one pixel (monochrome)
voidset_pixel(unsigned long x,
unsigned long y,
double r,
double g,
double b)
Set one pixel (color)
[const]stringto_sConver the image to a string
[const]DCplxTranstransReturn the pixel-to-micron transformation
voidtrans=(const DCplxTrans t)Set the transformation
[const]Imagetransformed(const DTrans t)Transform the image with the given simple transformation
[const]Imagetransformed(const Matrix3d t)Transform the image with the given matrix transformation
[const]Imagetransformed(const DCplxTrans t)Transform the image with the given complex transformation
[const]Imagetransformed_cplx(const DCplxTrans t)Transform the image with the given complex transformation
[const]Imagetransformed_matrix(const Matrix3d t)Transform the image with the given matrix transformation
voidvisible=(bool v)Set the visibility
[const]unsigned longwidthGet the width of the image in pixels

Deprecated methods (protected, public, static, non-static and constructors)

voidcreateUse of this method is deprecated. Use _create instead
voiddestroyUse of this method is deprecated. Use _destroy instead
[const]booldestroyed?Use of this method is deprecated. Use _destroyed? instead
[const]boolis_const_object?Use of this method is deprecated. Use _is_const_object? instead

Detailed description

void _create

Description: Ensures the C++ object is created

Use this method to ensure the C++ object is created, for example to ensure that resources are allocated. Usually C++ objects are created on demand and not necessarily when the script object is created.

void _destroy

Description: Explicitly destroys the object

Explicitly destroys the object on C++ side if it was owned by the script interpreter. Subsequent access to this object will throw an exception. If the object is not owned by the script, this method will do nothing.

[const] bool _destroyed?

Description: Returns a value indicating whether the object was already destroyed

This method returns true, if the object was destroyed, either explicitly or by the C++ side. The latter may happen, if the object is owned by a C++ object which got destroyed itself.

[const] bool _is_const_object?

Description: Returns a value indicating whether the reference is a const reference

This method returns true, if self is a const reference. In that case, only const methods may be called on self.

void _manage

Description: Marks the object as managed by the script side.

After calling this method on an object, the script side will be responsible for the management of the object. This method may be called if an object is returned from a C++ function and the object is known not to be owned by any C++ instance. If necessary, the script side may delete the object if the script's reference is no longer required.

Usually it's not required to call this method. It has been introduced in version 0.24.

void _unmanage

Description: Marks the object as no longer owned by the script side.

Calling this method will make this object no longer owned by the script's memory management. Instead, the object must be managed in some other way. Usually this method may be called if it is known that some C++ object holds and manages this object. Technically speaking, this method will turn the script's reference into a weak reference. After the script engine decides to delete the reference, the object itself will still exist. If the object is not managed otherwise, memory leaks will occur.

Usually it's not required to call this method. It has been introduced in version 0.24.

void assign(const Image other)

Description: Assigns another object to self

[const] DBox box

Description: Get the bounding box of the image

Returns:The bounding box

void create

Description: Ensures the C++ object is created

Use of this method is deprecated. Use _create instead

[const] ImageDataMapping data_mapping

Description: Get the data mapping

Returns:The data mapping object

The data mapping describes the transformation of a pixel value (any double value) into pixel data which can be sent to the graphics cards for display. See ImageDataMapping for a more detailed description.

Python specific notes:

The object exposes a readable attribute 'data_mapping'. This is the getter.

void data_mapping=(const ImageDataMapping data_mapping)

Description: Set the data mapping object

The data mapping describes the transformation of a pixel value (any double value) into pixel data which can be sent to the graphics cards for display. See ImageDataMapping for a more detailed description.

Python specific notes:

The object exposes a writable attribute 'data_mapping'. This is the setter.

void destroy

Description: Explicitly destroys the object

Use of this method is deprecated. Use _destroy instead

[const] bool destroyed?

Description: Returns a value indicating whether the object was already destroyed

Use of this method is deprecated. Use _destroyed? instead

[const] new Image ptr dup

Description: Creates a copy of self

[const] string filename

Description: Get the name of the file loaded of an empty string if not file is loaded

Returns:The file name (path)

[const] double get_pixel(unsigned long x,unsigned long y)

Description: Accessor to one pixel (monochrome and color)

x:The x coordinate of the pixel (0..width()-1)
y:The y coordinate of the pixel (mathematical order: 0 is the lowest, 0..height()-1)
component:0 for red, 1 for green, 2 for blue.

If the component index, x or y value exceeds the image bounds, this method returns 0.0. For monochrome images, the component index is ignored.

[const] double get_pixel(unsigned long x,unsigned long y,unsigned int component)

Description: Accessor to one pixel (monochrome and color)

x:The x coordinate of the pixel (0..width()-1)
y:The y coordinate of the pixel (mathematical order: 0 is the lowest, 0..height()-1)
component:0 for red, 1 for green, 2 for blue.

If the component index, x or y value exceeds the image bounds, this method returns 0.0. For monochrome images, the component index is ignored.

[const] unsigned long height

Description: Get the height of the image in pixels

Returns:The height in pixels

[const] int id

Description: Get the Id

The Id is an arbitrary integer that can be used to track the evolution of an image object. The Id is not changed when the object is edited. On initialization, a unique Id is given to the object. The Id cannot be changed. This behaviour has been modified in version 0.20.

[const] bool is_color?

Description: Returns true, if the image is a color image

Returns:True, if the image is a color image

[const] bool is_const_object?

Description: Returns a value indicating whether the reference is a const reference

Use of this method is deprecated. Use _is_const_object? instead

[const] bool is_empty?

Description: Returns true, if the image does not contain any data (i.e. is default constructed)

Returns:True, if the image is empty

[const] bool is_visible?

Description: Gets a flag indicating whether the image object is visible

An image object can be made invisible by setting the visible property to false.

This method has been introduced in version 0.20.

[const] bool mask(unsigned long x,unsigned long y)

Description: Gets the mask for one pixel

x:The x coordinate of the pixel (0..width()-1)
y:The y coordinate of the pixel (mathematical order: 0 is the lowest, 0..height()-1)
Returns:false if the pixel is not drawn.

See set_mask for details about the mask.

This method has been introduced in version 0.23.

[const] Matrix3d matrix

Description: Return the pixel-to-micron transformation matrix

This transformation matrix converts pixel coordinates (0,0 being the center and each pixel having the dimension of pixel_width and pixel_height) to micron coordinates. The coordinate of the pixel is the lower left corner of the pixel.

The matrix is more general than the transformation used before and supports shear and perspective transformation. This property replaces the trans property which is still functional, but deprecated.

This method has been introduced in version 0.22.

Python specific notes:

The object exposes a readable attribute 'matrix'. This is the getter.

void matrix=(const Matrix3d t)

Description: Set the transformation matrix

This transformation matrix converts pixel coordinates (0,0 being the center and each pixel having the dimension of pixel_width and pixel_height) to micron coordinates. The coordinate of the pixel is the lower left corner of the pixel.

The matrix is more general than the transformation used before and supports shear and perspective transformation. This property replaces the trans property which is still functional, but deprecated.

This method has been introduced in version 0.22.

Python specific notes:

The object exposes a writable attribute 'matrix'. This is the setter.

[const] double max_value

Description: Set the maximum value

See the max_value method for the description of the maximum value property.

Python specific notes:

The object exposes a readable attribute 'max_value'. This is the getter.

void max_value=(double v)

Description: Get the upper limit of the values in the data set

This value determines the upper end of the data mapping (i.e. white value etc.). It does not necessarily correspond to the maximum value of the data set but it must be larger than that.

Python specific notes:

The object exposes a writable attribute 'max_value'. This is the setter.

[const] double min_value

Description: Get the upper limit of the values in the data set

This value determines the upper end of the data mapping (i.e. white value etc.). It does not necessarily correspond to the minimum value of the data set but it must be larger than that.

Python specific notes:

The object exposes a readable attribute 'min_value'. This is the getter.

void min_value=(double v)

Description: Set the minimum value

See min_value for the description of the minimum value property.

Python specific notes:

The object exposes a writable attribute 'min_value'. This is the setter.

[static] new Image ptr new

Description: Create a new image with the default attributes

This will create an empty image without data and no particular pixel width or related. Use the read_file or set_data methods to set image properties and pixel values.

Python specific notes:

This method is the default initializer of the object

[static] new Image ptr new(string filename)

Description: Constructor from a image file

filename:The path to the image file to load.

This constructor creates an image object from a file (which can have any format supported by Qt) and a unit transformation. The image will originally be put to position 0,0 (lower left corner) and each pixel will have a size of 1 (micron).

Python specific notes:

This method is the default initializer of the object

[static] new Image ptr new(string filename,const DCplxTrans trans)

Description: Constructor from a image file

filename:The path to the image file to load.
trans:The transformation to apply to the image when displaying it.

This constructor creates an image object from a file (which can have any format supported by Qt) and a transformation. The image will originally be put to position 0,0 (lower left corner) and each pixel will have a size of 1. The transformation describes how to transform this image into micron space.

Python specific notes:

This method is the default initializer of the object

[static] new Image ptr new(unsigned long w,unsigned long h,double[] data)

Description: Constructor for a monochrome image with the given pixel values

w:The width of the image
h:The height of the image
d:The data (see method description)

This constructor creates an image from the given pixel values. The values have to be organized line by line. Each line must consist of "w" values where the first value is the leftmost pixel. Note, that the rows are oriented in the mathematical sense (first one is the lowest) contrary to the common convention for image data. Initially the pixel width and heigt will be 1 micron and the data range will be 0 to 1.0 (black to white level). To adjust the data range use the min_value and max_value properties.

Python specific notes:

This method is the default initializer of the object

[static] new Image ptr new(unsigned long w,unsigned long h,const DCplxTrans trans,double[] data)

Description: Constructor for a monochrome image with the given pixel values

w:The width of the image
h:The height of the image
trans:The transformation from pixel space to micron space
d:The data (see method description)

This constructor creates an image from the given pixel values. The values have to be organized line by line. Each line must consist of "w" values where the first value is the leftmost pixel. Note, that the rows are oriented in the mathematical sense (first one is the lowest) contrary to the common convention for image data. Initially the pixel width and heigt will be 1 micron and the data range will be 0 to 1.0 (black to white level). To adjust the data range use the min_value and max_value properties.

Python specific notes:

This method is the default initializer of the object

[static] new Image ptr new(unsigned long w,unsigned long h,double[] red,double[] green,double[] blue)

Description: Constructor for a color image with the given pixel values

w:The width of the image
h:The height of the image
red:The red channel data set which will become owned by the image
green:The green channel data set which will become owned by the image
blue:The blue channel data set which will become owned by the image

This constructor creates an image from the given pixel values. The values have to be organized line by line and separated by color channel. Each line must consist of "w" values where the first value is the leftmost pixel. Note, that the rows are oriented in the mathematical sense (first one is the lowest) contrary to the common convention for image data. Initially the pixel width and heigt will be 1 micron and the data range will be 0 to 1.0 (black to white level). To adjust the data range use the min_value and max_value properties.

Python specific notes:

This method is the default initializer of the object

[static] new Image ptr new(unsigned long w,unsigned long h,const DCplxTrans trans,double[] red,double[] green,double[] blue)

Description: Constructor for a color image with the given pixel values

w:The width of the image
h:The height of the image
trans:The transformation from pixel space to micron space
red:The red channel data set which will become owned by the image
green:The green channel data set which will become owned by the image
blue:The blue channel data set which will become owned by the image

This constructor creates an image from the given pixel values. The values have to be organized line by line and separated by color channel. Each line must consist of "w" values where the first value is the leftmost pixel. Note, that the rows are oriented in the mathematical sense (first one is the lowest) contrary to the common convention for image data. Initially the pixel width and heigt will be 1 micron and the data range will be 0 to 1.0 (black to white level). To adjust the data range use the min_value and max_value properties.

Python specific notes:

This method is the default initializer of the object

[const] double pixel_height

Description: Get the pixel height

See pixel_height= for a description of that property.

Starting with version 0.22, this property is incorporated into the transformation matrix. This property is provided for convenience only.

Python specific notes:

The object exposes a readable attribute 'pixel_height'. This is the getter.

void pixel_height=(double h)

Description: Set the pixel height

The pixel height determines the height of on pixel in the original space which is transformed to micron space with the transformation.

Starting with version 0.22, this property is incorporated into the transformation matrix. This property is provided for convenience only.

Python specific notes:

The object exposes a writable attribute 'pixel_height'. This is the setter.

[const] double pixel_width

Description: Get the pixel width

See pixel_width= for a description of that property.

Starting with version 0.22, this property is incorporated into the transformation matrix. This property is provided for convenience only.

Python specific notes:

The object exposes a readable attribute 'pixel_width'. This is the getter.

void pixel_width=(double w)

Description: Set the pixel width

The pixel width determines the width of on pixel in the original space which is transformed to micron space with the transformation.

Starting with version 0.22, this property is incorporated into the transformation matrix. This property is provided for convenience only.

Python specific notes:

The object exposes a writable attribute 'pixel_width'. This is the setter.

void set_data(unsigned long w,unsigned long h,double[] d)

Description: Write the image data field (monochrome)

w:The width of the new data
h:The height of the new data
d:The (monochrome) data to load into the image

See the constructor description for the data organisation in that field.

void set_data(unsigned long w,unsigned long h,double[] r,double[] g,double[] b)

Description: Write the image data field (color)

w:The width of the new data
h:The height of the new data
r:The red channel data to load into the image
g:The green channel data to load into the image
b:The blue channel data to load into the image

See the constructor description for the data organisation in that field.

void set_mask(unsigned long x,unsigned long y,bool m)

Description: Set the mask for a pixel

x:The x coordinate of the pixel (0..width()-1)
y:The y coordinate of the pixel (mathematical order: 0 is the lowest, 0..height()-1)
m:The mask

If the mask of a pixel is set to false, the pixel is not drawn. The default is true for all pixels.

This method has been introduced in version 0.23.

void set_pixel(unsigned long x,unsigned long y,double v)

Description: Set one pixel (monochrome)

x:The x coordinate of the pixel (0..width()-1)
y:The y coordinate of the pixel (mathematical order: 0 is the lowest, 0..height()-1)
v:The value

If the component index, x or y value exceeds the image bounds of the image is a color image, this method does nothing.

void set_pixel(unsigned long x,unsigned long y,double r,double g,double b)

Description: Set one pixel (color)

x:The x coordinate of the pixel (0..width()-1)
y:The y coordinate of the pixel (mathematical order: 0 is the lowest, 0..height()-1)
red:The red component
green:The green component
blue:The blue component

If the component index, x or y value exceeds the image bounds of the image is not a color image, this method does nothing.

[const] string to_s

Description: Conver the image to a string

Returns:The string

Python specific notes:

This method is also available as 'str(object)'

[const] DCplxTrans trans

Description: Return the pixel-to-micron transformation

This transformation converts pixel coordinates (0,0 being the lower left corner and each pixel having the dimension of pixel_width and pixel_height) to micron coordinates. The coordinate of the pixel is the lower left corner of the pixel.

The general property is matrix which also allows perspective and shear transformation. This property will only work, if the transformation does not include perspective or shear components. Therefore this property is deprecated. Please note that for backward compatibility, the rotation center is pixel 0,0 (lowest left one), while it is the image center for the matrix transformation.

Python specific notes:

The object exposes a readable attribute 'trans'. This is the getter.

void trans=(const DCplxTrans t)

Description: Set the transformation

This transformation converts pixel coordinates (0,0 being the lower left corner and each pixel having the dimension of pixel_width and pixel_height) to micron coordinates. The coordinate of the pixel is the lower left corner of the pixel.

The general property is matrix which also allows perspective and shear transformation. Please note that for backward compatibility, the rotation center is pixel 0,0 (lowest left one), while it is the image center for the matrix transformation.

Python specific notes:

The object exposes a writable attribute 'trans'. This is the setter.

[const] Image transformed(const DTrans t)

Description: Transform the image with the given simple transformation

t:The transformation to apply
Returns:The transformed object

[const] Image transformed(const Matrix3d t)

Description: Transform the image with the given matrix transformation

t:The transformation to apply (a matrix)
Returns:The transformed object

This method has been introduced in version 0.22.

[const] Image transformed(const DCplxTrans t)

Description: Transform the image with the given complex transformation

t:The magnifying transformation to apply
Returns:The transformed object

[const] Image transformed_cplx(const DCplxTrans t)

Description: Transform the image with the given complex transformation

t:The magnifying transformation to apply
Returns:The transformed object

[const] Image transformed_matrix(const Matrix3d t)

Description: Transform the image with the given matrix transformation

t:The transformation to apply (a matrix)
Returns:The transformed object

This method has been introduced in version 0.22.

void visible=(bool v)

Description: Set the visibility

See the is_visible? method for a description of this property.

This method has been introduced in version 0.20.

Python specific notes:

The object exposes a writable attribute 'visible'. This is the setter.

[const] unsigned long width

Description: Get the width of the image in pixels

Returns:The width in pixels