BrownModel

giant.camera_models.brown_model:

class giant.camera_models.brown_model.BrownModel(intrinsic_matrix=None, fx=None, fy=None, px=None, py=None, alpha=None, kx=None, ky=None, kxy=None, field_of_view=None, use_a_priori=False, distortion_coefficients=None, k1=None, k2=None, k3=None, p1=None, p2=None, radial2=None, radial4=None, radial6=None, tiptilt_y=None, tiptilt_x=None, temperature_coefficients=None, a1=None, a2=None, a3=None, misalignment=None, estimation_parameters='basic', n_rows=1, n_cols=1)[source]

Bases: PinholeModel

This class provides an implementation of the Brown camera model for projecting 3D points onto images and performing camera calibration.

The BrownModel class is a subclass of PinholeModel. This means that it includes implementations for all of the abstract methods defined in the CameraModel class. This also means that it can be used throughout GIANT as the primary camera model, including within the calibration subpackage. If this class is going to be used with the calibration subpackage, the user can set which parameters are estimated and which are held fixed by using the estimation_parameters keyword argument when creating an instance of the class or by adjusting the estimation_parameters attribute on an instance of the class. The estimation_parameters input/attribute is a string or list of strings specifying which parameters to estimate. This means that estimation_parameters could be something like 'basic' which would indicate to estimate just the usual parameters, or something like ['fx', 'fy', 'px', 'py'] to estimate just the terms included in the list.

In addition to the standard set of methods for a CameraModel subclass, the BrownModel class provides the following additional methods which may or may not be useful to some people:

Method

Use

get_projections()

computes the pinhole, image frame, and pixel locations of a 3D point

pixels_to_gnomic()

removes distortion from a point to get the corresponding unitless pinhole location

The BrownModel class also provides the following properties for easy getting/setting:

Property

Description

field_of_view

the diagonal field of view of the camera in units of degrees

kx, fx

\(f_x\), focal length divided by the pixel pitch in the x direction in units of pixels

ky, fy

\(f_y\), focal length divided by the pixel pitch in the y direction in units of pixels

kxy, alpha

\(\alpha\), A alpha term for non-rectangular pixels

px

\(p_{x}\), the x axis pixel location of the principal point of the camera in units of pixels

py

\(p_{y}\), the y axis pixel location of the principal point of the camera in units of pixels

radial2, k1

\(k_1\), the radial distortion coefficient corresponding to \(r^2\)

radial4, k2

\(k_2\), the radial distortion coefficient corresponding to \(r^4\)

radial6, k3

\(k_3\), the radial distortion coefficient corresponding to \(r^6\)

tiptilt_y, p1

\(p_1\), the tip/tilt/prism distortion coefficient corresponding to \(y_I\)

tiptilt_x, p2

\(p_2\), the tip/tilt/prism distortion coefficient corresponding to \(x_I\)

a1

\(a_1\), the linear coefficient for focal length dependent focal length

a2

\(a_2\), the quadratic coefficient for focal length dependent focal length

a3

\(a_3\), the cubic coefficient for focal length dependent focal length

intrinsic_matrix_inv

The inverse of the intrinsic matrix

Note

The distortion attributes are aliases over each other and refer to the same data. Therefore setting a value to radial2 would also change the value of k1

Parameters:
  • intrinsic_matrix (Sequence | ndarray | None) – the intrinsic matrix for the camera as a numpy shape (2, 3) array. Note that this is overwritten if kx, ky, kxy, kyx, px, py, fx, fy, alpha are also specified.

  • field_of_view (Real | None) – The field of view of the camera in units of degrees.

  • use_a_priori (bool) – A flag to indicate whether to include the a priori state vector in the Jacobian matrix when performing a calibration

  • distortion_coefficients (Sequence | ndarray | None) – A numpy array of shape (6,) containing the six distortion coefficients in order. Note that this array is overwritten with any distortion coefficients that are specified independently.

  • misalignment (Sequence | ndarray | None) – either a numpy array of shape (3,) or a list of numpy arrays of shape(3,) with each array corresponding to a single image (the list of numpy arrays is only valid when estimating multiple misalignments)

  • estimation_parameters (str | Sequence) – A string or list of strings specifying which model parameters to include in the calibration

  • fx (Real | None) – The pixel pitch along the x axis in units of pixels

  • fy (Real | None) – The pixel pitch along the y axis in units of pixels

  • kx (Real | None) – The pixel pitch along the x axis in units of pixels

  • ky (Real | None) – The pixel pitch along the y axis in units of pixels

  • kxy (Real | None) – A alpha term for non-rectangular pixels

  • alpha (Real | None) – An alpha term for non-rectangular pixels

  • px (Real | None) – the x component of the pixel location of the principal point in the image in units of pixels

  • py (Real | None) – the y component of the pixel location of the principal point in the image in units of pixels

  • radial2 (Real | None) – the radial distortion coefficient corresponding to the r**2 term

  • radial4 (Real | None) – the radial distortion coefficient corresponding to the r**4 term

  • radial6 (Real | None) – the radial distortion coefficient corresponding to the r**4 term

  • k1 (Real | None) – the radial distortion coefficient corresponding to the r**2 term

  • k2 (Real | None) – the radial distortion coefficient corresponding to the r**4 term

  • k3 (Real | None) – the radial distortion coefficient corresponding to the r**4 term

  • tiptilt_y (Real | None) – the tip/tilt/decentering distortion coefficient corresponding to the y term

  • tiptilt_x (Real | None) – the tip/tilt/decentering distortion coefficient corresponding to the x term

  • p1 (Real | None) – the tip/tilt/decentering distortion coefficient corresponding to the y term

  • p2 (Real | None) – the tip/tilt/decentering distortion coefficient corresponding to the x term

  • n_rows (int) – the number of rows of the active image array

  • n_cols (int) – the number of columns in the active image array

  • temperature_coefficients (Sequence | ndarray | None) –

  • a1 (Real | None) –

  • a2 (Real | None) –

  • a3 (Real | None) –

n_rows

The number of rows in the active pixel array for the camera

n_cols

The number of columns in the active pixel array for the camera

use_a_priori

This boolean value is used to determine whether to append the identity matrix to the Jacobian matrix returned by compute_jacobian() in order to include the current estimate of the camera model in the calibration process.

intrinsic_matrix

The 2x3 intrinsic matrix contains the conversion from unitless gnomic locations to a location in an image with units of pixels.

It is defined as

\[\begin{split}\mathbf{K} = \left[\begin{array}{ccc} f_x & \alpha & p_x \\ 0 & f_y & p_y \end{array}\right]\end{split}\]
temperature_coefficients

The coefficients for the polynomial specifying the change in the focal length as a function of temperature.

estimate_multiple_misalignments

This boolean value is used to determine whether multiple misalignments are being estimated/used per image.

If set to True then one misalignment is estimated for each image and used for each image when projecting through the camera model. When set to False then a single misalignment is estimated for all images and used for all images when projecting through the camera model. Typically the user shouldn’t be setting this attribute directly as it is automatically handled when setting the estimation_parameters attribute.

estimation_parameters

A list of strings containing the parameters to estimate when performing calibration with this model.

This list is used in the methods compute_jacobian() and apply_update() to determine which parameters are being estimated/updated. From the compute_jacobian() method, only columns of the Jacobian matrix corresponding to the parameters in this list are returned. In the apply_update() method, the update vector elements are assumed to correspond to the order expressed in this list.

Valid values for the elements of this list are shown in the following table. Generally, they correspond to attributes of this class, with a few convenient aliases that point to a collection of attributes.

Value

Description

'basic'

estimate fx, fy, alpha all 5 distortion parameters, and a single misalignment term for all images between the camera attitude and the spacecraft’s attitude: \(\left[\begin{array}{cccccccccc} f_x & f_y & \alpha & k_1 & k_2 & k_3 & p_1 & p_2 & \boldsymbol{\delta\theta} \end{array}\right]\)

'intrinsic'

estimate fx, fy, alpha, px, py, and all 5 distortion parameters: \(\left[\begin{array}{ccccccccccccc} f_x & f_y & \alpha & p_x & p_y & k_1 & k_2 & k_3 & p_1 & p_2 \end{array}\right]\)

'basic intrinsic'

estimate fx, fy, alpha, and all 5 distortion parameters: \(\left[\begin{array}{ccccccccc} f_x & f_y & \alpha & k1 & k_2 & k_3 & p_1 & p_2 \end{array}\right]\)

'temperature dependence'

estimate a 3rd order polynomial for temperature dependence: \(\left[\begin{array}{ccc} a_1 & a_2 & a_3 \end{array}\right]\)

'fx', 'kx'

focal length divided by pixel pitch along the x axis: \(f_x\)

'alpha', 'kxy'

alpha term for non-rectangular/rotated pixels: \(\alpha\)

'fy', 'ky'

focal length divided by pixel pitch along the y axis: \(f_y\)

'px'

x location of the principal point: \(p_x\)

'py'

y location of the principal point: \(p_y\)

'radial2', 'k1'

distortion coefficient corresponding to the \(r^2\) term: \(k_1\)

'radial4', 'k2'

distortion coefficient corresponding to the \(r^4\) term: \(k_2\)

'radial6', 'k3'

distortion coefficient corresponding to the \(r^6\) term: \(k_3\)

'tiptilt_y, 'p1'

distortion coefficient corresponding to the y tip/tilt distortion: \(p_1\)

'tiptilt_x, 'p2'

distortion coefficient corresponding to the x tip/tilt distortion: \(p_2\)

'a1'

estimate the linear coefficient for the temperature dependence: \(a_1\)

'a2'

estimate the quadratice coefficient for the temperature dependence: \(a_2\)

'a3'

estimate the cubic coefficient for the temperature dependence: \(a_3\)

'single misalignment'

estimate a single misalignment for all images: \(\boldsymbol{\delta\theta}\)

'multiple misalignments'

estimate a misalignment for each image: \(\left[\begin{array}{ccc}\boldsymbol{\delta\theta}_1 & \ldots & \boldsymbol{\delta\theta}_n \end{array}\right]\)

Note that it may not be possible to estimate all attributes simultaneously because this may result in a rank deficient matrix in the calibration process (for instance, without setting a priori weights, estimating 'px', 'py', and 'multiple misalignments' together could result in a rank deficient matrix. Therefore, just because you can set something in this list doesn’t mean you should.

For more details about calibrating a camera model, see the calibration package for details.

distortion_coefficients

The distortion coefficients array contains the distortion coefficients for the Brown model [k1, k2, k3, p1, p2]

property field_of_view: float

A radial field of view of the camera specified in degrees.

The field of view should be set to at least the half width diagonal field of view of the camera. The field of view is used when querying star catalogues.

The diagonal field of view is defined as

+-----------+
|          /|
|         / |
|        /  |
|      V/   |
|     O/    |
|    F/     |
|   */      |
|  2/       |
|  /        |
| /         |
|/          |
+-----------+

If you specify this parameter to be None, the field of view will be computed using the camera model if possible.

property fx: float

The focal length in units of pixels along the x axis (focal length divided by x axis pixel pitch)

This is an alias to kx and points to the (0, 0) index of the intrinsic matrix

property fy: float

The focal length in units of pixels along the y axis (focal length divided by y axis pixel pitch)

This is an alias to ky and points to the (1, 1) index of the intrinsic matrix

property kxy: float

An alpha term for non-rectangular pixels.

This corresponds to the [0, 1] component of the intrinsic matrix

property alpha: float

An alpha term for non-rectangular pixels.

This is an alias to kxy and points to the to the [0, 1] component of the intrinsic matrix

property kx: float

The inverse of the pixel pitch along the x axis in units of pix/distance.

This is the conversion factor to convert from gnomic coordinates (in units of distance) to units of pixels. It corresponds to the [0, 0] component of the intrinsic matrix

property ky: float

The inverse of the pixel pitch along the y axis in units of pix/distance.

This is the conversion factor to convert from pinhole coordinates (in units of distance) to units of pixels. It corresponds to the [1, 1] component of the intrinsic matrix

property px: float

The x pixel location of the principal point of the camera.

The principal point of the camera is the point in the image where the distortion is zero (the point where the optical axis pierces the image). This corresponds to the [0, 2] component of the intrinsic matrix

property py: float

The y pixel location of the principal point of the camera.

The principal point of the camera is the point in the image where the distortion is zero (the point where the optical axis pierces the image). This corresponds to the [1, 2] component of the intrinsic matrix

property a1: float

The linear coefficient for the focal length temperature dependence

This is the first term in the temperature_coefficients array and is multiplied by the temperature.

property a2: float

The quadratic coefficient for the focal length temperature dependence

This is the second term in the temperature_coefficients array and is multiplied by the temperature squared.

property a3: float

The cubic coefficient for the focal length temperature dependence

This is the third term in the temperature_coefficients array and is multiplied by the temperature cubed.

property k1: float

The radial distortion coefficient corresponding to the r**2 term

This corresponds to the [0] index of the distortion_coefficients array

property state_vector: List[Real]

Returns the fully realized state vector according to estimation_parameters as a length l list.

property k2: float

The radial distortion coefficient corresponding to the r**4 term

This corresponds to the [1] index of the distortion_coefficients array

property k3: float

The radial distortion coefficient corresponding to the r**6 term

This corresponds to the [2] index of the distortion_coefficients array

property p1: float

The tip/tilt/decentering distortion coefficient corresponding to the y term.

This corresponds to the [3] index of the distortion_coefficients array.

property p2: float

The tip/tilt/decentering distortion coefficient corresponding to the x term.

This corresponds to the [4] index of the distortion_coefficients array.

property radial2: float

The radial distortion coefficient corresponding to the r**2 term

This is an alias to the k1 attribute and corresponds to the [0] index of the distortion_coefficients array

property radial4: float

The radial distortion coefficient corresponding to the r**4 term

This is an alias to the k2 attribute and corresponds to the [1] index of the distortion_coefficients array

property radial6: float

The radial distortion coefficient corresponding to the r**6 term

This is an alias to the k3 attribute and corresponds to the [2] index of the distortion_coefficients array

property tiptilt_y: float

The tip/tilt/decentering distortion coefficient corresponding to the y term.

This is an alias to the p1 attribute and corresponds to the [3] index of the distortion_coefficients array

property tiptilt_x: float

The tip/tilt/decentering distortion coefficient corresponding to the x term.

This is an alias to the p2 attribute and corresponds to the [3] index of the distortion_coefficients array

property intrinsic_matrix_inv: ndarray

The inverse of the intrinsic matrix.

The inverse of the intrinsic matrix is used to convert from units of pixels with an origin at the upper left corner of the image to units of distance with an origin at the principal point of the image.

the intrinsic matrix has an analytic inverse which is given by

\[\begin{split}\mathbf{K}^{-1} = \left[\begin{array}{ccc} \frac{1}{f_x} & -\frac{\alpha}{f_xf_y} & \frac{\alpha p_y-f_yp_x}{f_xf_y} \\ 0 & \frac{1}{f_y} & \frac{-p_y}{f_y} \end{array}\right]\end{split}\]
To convert from units of pixels to a unitless, distorted gnomic location you would do::
>>> from giant.camera_models import BrownModel
>>> model = BrownModel(kx=5, ky=10, px=100, py=500)
>>> ((model.intrinsic_matrix_inv[:, :2]@[[1, 2, 300], [4, 5, 600]]).T + model.intrinsic_matrix_inv[:, 2]).T
array([[-19.8, -19.6, 40.]
       [-49.6, -49.5, 10.]])

Note

The above code will give you distorted gnomic location, while the pixels_to_gnomic() will give you undistorted gnomic locations (true pinhole points).

Note

Since the intrinsic matrix is defined as a \(2\times 3\) matrix this isn’t a formal inverse. To get the true inverse you need to append a row of [0, 0, 1] to both the intrinsic matrix and intrinsic matrix inverse.

Summary of Methods

project_onto_image

This method transforms 3D points or directions expressed in the camera frame into the corresponding 2D image locations.

project_directions

This method transforms 3D directions expressed in the camera frame into the corresponding 2D image directions.

compute_jacobian

Calculates the Jacobian matrix for each observation in unit_vectors_camera for each parameter to be estimated as defined in the estimation_parameters attribute.

compute_pixel_jacobian

This method computes the Jacobian matrix \(\partial\mathbf{x}_P/\partial\mathbf{x}_C\) where \(\mathbf{x}_C\) is a vector in the camera frame that projects to \(\mathbf{x}_P\) which is the pixel location.

compute_unit_vector_jacobian

This method computes the Jacobian matrix \(\partial\mathbf{x}_C/\partial\mathbf{x}_P\) where \(\mathbf{x}_C\) is a vector in the camera frame that projects to \(\mathbf{x}_P\) which is the pixel location.

apply_update

This method takes in a delta update to camera parameters (\(\Delta\mathbf{c}\)) and applies the update to the current instance in place.

pixels_to_unit

This method converts pixel image locations to unit vectors expressed in the camera frame.

undistort_pixels

This method computes undistorted pixel locations (gnomic/pinhole locations) for given distorted pixel locations according to the current model.

distort_pixels

A method that takes gnomic pixel locations in units of pixels and applies the appropriate distortion to them.

overwrite

This method replaces self with the properties of model in place.

distortion_map

This method computes the value of the distortion model across an entire image for use in creating distortion maps.

undistort_image

This method takes in an entire image and warps it to remove the distortion specified by the current model.

copy

Returns a deep copy of this object, breaking all references with self.

to_elem

Stores this camera model in an etree._Element object for storing in a GIANT xml file

from_elem

This class method is used to construct a new instance of cls from an etree._Element object

adjust_temperature

This method adjusts a pixel location to reflect a new image temperature.

get_temperature_scale

This method computes the scaling to the focal length caused by a shift in temperature.

pixels_to_gnomic

This method takes an input in pixels and computes the undistorted gnomic location in units of distance.

prepare_interp

This method prepares a SciPy RegularGridInterpolator for converting pixels into undistorted gnomic locations.

pixels_to_gnomic_interp

This method takes an input in pixels and approximates the undistorted gnomic location in units of distance.

get_projections

This method computes and returns the pinhole, and pixel locations for a set of 3D points expressed in the camera frame.

apply_distortion

This method applies the distortion model to the specified pinhole (gnomic) locations in the image frame.

get_state_labels

Convert a list of estimation parameters into state label names.

reset_misalignment

This method reset the misalignment terms to all be zero (no misalignment).

get_misalignment

This method returns the Rotation object for the misalignment for the requested image.