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 ImagenewCreate a new image with the default attributes
new Imagenew(string filename)Constructor from a image file
new Imagenew(string filename,
const DCplxTrans trans)
Constructor from a image file
new Imagenew(unsigned int w,
unsigned int h,
double[] data)
Constructor for a monochrome image with the given pixel values
new Imagenew(unsigned int w,
unsigned int h,
const DCplxTrans trans,
double[] data)
Constructor for a monochrome image with the given pixel values
new Imagenew(unsigned int w,
unsigned int h,
double[] red,
double[] green,
double[] blue)
Constructor for a color image with the given pixel values
new Imagenew(unsigned int w,
unsigned int h,
const DCplxTrans trans,
double[] red,
double[] green,
double[] blue)
Constructor for a color image with the given pixel values

Public methods

[const]voidassign(const Image other)Assign the contents of another object to self
[const]DBoxboxGet the bounding box of the image
voidcreateEnsures the C++ object is created
[const]ImageDataMappingdata_mappingGet the data mapping
voiddata_mapping=(const ImageDataMapping data_mapping)Set the data mapping object
voiddestroyExplicitly destroy the object
[const]booldestroyed?Returns a value indicating whether the object was already destroyed
[const]ImagedupCreates 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 int x,
unsigned int y)
Accessor to one pixel (monochrome and color)
[const]doubleget_pixel(unsigned int x,
unsigned int y,
unsigned int component)
Accessor to one pixel (monochrome and color)
[const]unsigned intheightGet 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_const_object?Returns a value indicating whether the reference is a const reference
[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 int x,
unsigned int 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 int w,
unsigned int h,
double[] d)
Write the image data field (monochrome)
voidset_data(unsigned int w,
unsigned int h,
double[] r,
double[] g,
double[] b)
Write the image data field (color)
voidset_mask(unsigned int x,
unsigned int y,
bool m)
Set the mask for a pixel
voidset_pixel(unsigned int x,
unsigned int y,
double v)
Set one pixel (monochrome)
voidset_pixel(unsigned int x,
unsigned int 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 intwidthGet the width of the image in pixels

Detailed description

[const] void assign(const Image other)

Description: Assign the contents of another object to self

This method assigns the contents of another object to self. This is a deep copy that does not only copy the reference but the actual content.

[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 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.

[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.

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.

void destroy

Description: Explicitly destroy the object

Explicitly destroy the object on C++ side if it was owned by the Ruby interpreter. Subsequent access to this object will throw an exception. If the object is not owned by Ruby, 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] Image 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 int x,unsigned int 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 int x,unsigned int 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 int 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

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

[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 int x,unsigned int 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.

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.

[const] double max_value

Description: Set the maximum value

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

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.

[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.

void min_value=(double v)

Description: Set the minimum value

See min_value for the description of the minimum value property.

[static] new Image 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.

[static] new Image 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).

[static] new Image 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.

[static] new Image new(unsigned int w,unsigned int 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.

[static] new Image new(unsigned int w,unsigned int 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.

[static] new Image new(unsigned int w,unsigned int 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.

[static] new Image new(unsigned int w,unsigned int 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.

[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.

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.

[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.

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.

void set_data(unsigned int w,unsigned int 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 int w,unsigned int 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 int x,unsigned int 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 int x,unsigned int 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 int x,unsigned int 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

[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.

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.

[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.

[const] unsigned int width

Description: Get the width of the image in pixels

Returns:The width in pixels