Image#

Image class#

class Image(image=None)[source]#

A class to represent a 2D image to interpolate gray or colors values.

The image is associated with an interpolation function to evaluate pixel values at arbitrary points in the image. The interpolation function is constructed using scipy.interpolate.RectBivariateSpline with cubic splines (kx=3, ky=3).

The coordinates system used for the image is the same as the one used in pycvcam (See documentation of pycvcam at https://artezaru.github.io/pycvcam/).

  • The pixel_coordinates are defined in the array coordinate system \((u, v)\) where \(u\) is the row index and \(v\) is the column index.

  • The image_coordinates are defined in the camera coordinate system \((x, y)\) where \(x\) is the column index and \(y\) is the row index.

Note

The image will be automatically converted to a floating point format numpy.float64 for interpolation but it stores as unsigned integer internally to save memory.

Parameters:

image (Optional[ArrayLike]) – The image that is viewed by the camera. The image have a shape of (height, width) or (height, width, channels). If not provided, the image will be set to None

Instantiate an Image object#

To instantiate an Image object, you need to provide the pixel data as a 2D numpy array or the file path to an image.

Image.from_array(image_data)

Create an Image object from raw image data.

Image.from_file(file_path)

Create an Image object by loading image data from a file.

Export Image data#

You can export the image data to a file or a numpy array.

Image.to_array()

Get a copy of the image data as a numpy array.

Image.to_file(file_path[, dtype])

Save the image to a file using OpenCV write function.

Accessing Image attributes#

You can access the image attributes through the Image object using the following properties.

Image.dtype

[Get] The data type of the image.

Image.is_color

[Get] Check if the image is a color image (3D array).

Image.is_grayscale

[Get] Check if the image is grayscale (2D array).

Image.image

[Get or Set] The image data.

Image.height

[Get] The height of the image.

Image.n_channels

[Get] The number of channels in the image.

Image.ndim

[Get] The number of dimensions of the image.

Image.shape

[Get] The shape of the image.

Image.width

[Get] The width of the image.

If the image is modified externally, you must call the method image_update to refresh the image data.

Image.image_update()

Indicate that the image has been updated.

Image.construct_interpolation_functions()

Construct the interpolation functions for the image.

Operating with Image data#

You can use the image data to interpolate pixel values at specific coordinates.

Image.copy()

Create a copy of the Image object.

Image.evaluate_image_at_image_points(...)

Evaluate the image at given image points.

Image.evaluate_image_at_pixel_points(...)

Evaluate the image at given pixel points.

Image.evaluate_image_jacobian_dx_at_pixel_points(...)

Evaluate the Jacobian of the image at given pixel points along the \(x\)-axis (columns).

Image.evaluate_image_jacobian_dy_at_pixel_points(...)

Evaluate the Jacobian of the image at given pixel points along the \(y\)-axis (rows).

Image.evaluate_image_jacobian_du_at_pixel_points(...)

Evaluate the Jacobian of the image at given pixel points along the \(u\)-axis (rows).

Image.evaluate_image_jacobian_dv_at_pixel_points(...)

Evaluate the Jacobian of the image at given pixel points along the \(v\)-axis (columns).

Image.evaluate_image_jacobian_dx_at_image_points(...)

Evaluate the Jacobian of the image at given image points along the \(x\)-axis (columns).

Image.evaluate_image_jacobian_dy_at_image_points(...)

Evaluate the Jacobian of the image at given image points along the \(y\)-axis (rows).

Image.evaluate_image_jacobian_du_at_image_points(...)

Evaluate the Jacobian of the image at given image points along the \(u\)-axis (rows).

Image.evaluate_image_jacobian_dv_at_image_points(...)

Evaluate the Jacobian of the image at given image points along the \(v\)-axis (columns).

Image.get_image_pixel_points([mask])

Create a grid of pixel points covering the entire image.

Image.get_image_image_points([mask])

Create a grid of image points covering the entire image.

Image.get_interpolation_function([channel])

Get the scipy interpolation function for the image.

Image.image_points_to_pixel_points(image_points)

Convert image points to pixel points.

Image.pixel_points_to_image_points(pixel_points)

Convert pixel points to image points.

Visualize Image data#

You can visualize the image using the built-in visualization method.

Image.visualize([region, rectangle, title, ...])

Visualize the image using Matplotlib or a specific region of the image.