magni.imaging.measurements._matrices module

Module providing public functions for the magni.imaging.measurements subpackage.

Routine listings

construct_measurement_matrix(coords, h, w)
Function for constructing a measurement matrix.
magni.imaging.measurements._matrices.construct_measurement_matrix(coords, h, w)[source]

Construct a measurement matrix extracting the specified measurements.

  • coords (ndarray) – The k floating point coordinates arranged into a 2D array where each row is a coordinate pair (x, y), such that coords has size k x 2.
  • h (int) – The height of the image measured in pixels.
  • w (int) – The width of the image measured in pixels.

Phi (magni.utils.matrices.Matrix) – The constructed measurement matrix.

See also

The matrix emulator class.


The function constructs two functions: one for extracting pixels at the coordinates specified and one for the transposed operation. These functions are then wrapped by a matrix emulator which is returned.


Create a dummy 5 by 5 pixel image and an example sampling pattern:

>>> import numpy as np, magni
>>> img = np.arange(25, dtype=np.float).reshape(5, 5)
>>> vec = magni.imaging.mat2vec(img)
>>> coords = magni.imaging.measurements.uniform_line_sample_image(
...              5, 5, 16., 17)

Sample the image in the ordinary way:

>>> unique = magni.imaging.measurements.unique_pixels(coords)
>>> samples_normal = img[unique[:, 1], unique[:, 0]]
>>> samples_normal = samples_normal.reshape((len(unique), 1))

Sample the image using the present function:

>>> from magni.imaging.measurements import construct_measurement_matrix
>>> matrix = construct_measurement_matrix(coords, *img.shape)
>>> samples_matrix =

Check that the two ways produce the same result:

>>> np.allclose(samples_matrix, samples_normal)