geometric_calibration package

Top-level package for Geometric Calibration.

Submodules

geometric_calibration.cli module

geometric_calibration.geometric_calibration module

geometric_calibration.reader module

This module contains some function for I/O purposes.

geometric_calibration.reader.read_bbs_ref_file(filename)[source]

Read phantom reference file with bbs coordinates

Parameters:filename (str) – path to file
Returns:Array containing bbs coordinates [x,y,z]
Return type:numpy.array
geometric_calibration.reader.read_img_label_file(filename)[source]

Read imgLabels.txt file contained in .raw projection’s directory. This File contains information about path and the gantry angle of every .raw projection.

Parameters:filename (str) – path to file
Returns:list with path and list with angles for every row in imgLabels.txt file
Return type:list
geometric_calibration.reader.read_projection_hnc(filename, dim)[source]

Read .hnc file and load it into a Numpy array.

Parameters:
  • filename (str) – path to file
  • dim (list) – Dimension of image
Returns:

array containing loaded .raw image

Return type:

numpy.array

geometric_calibration.reader.read_projection_raw(filename, dim)[source]

Read .raw file and load it into a Numpy array.

Parameters:
  • filename (str) – path to file
  • dim (list) – Dimension of image
Returns:

array containing loaded .raw image

Return type:

numpy.array

geometric_calibration.dlt module

geometric_calibration.dlt.DLTcalib(nd, xyz, uv, uv_ref=None)[source]

Camera calibration by DLT using known object points and their corresponding image points. The coordinates (x,y,z and u,v) are given as columns and the different points as rows. There must be at least 6 calibration points for the 3D DLT.

Parameters:
  • nd (int) – dimensions of the object space, typically 3
  • xyz (numpy.array) – coordinates in the object 3D space
  • uv (numpy.array) – coordinates in the image 2D space
  • uv_ref (numpy.array, optional) – [description]. Defaults to None.
Raises:
  • ValueError – Dimension not supported
  • ValueError – xyz and uv have different number of points
  • ValueError – Wrong dimension for coordinates
  • ValueError – Insufficient number of points
Returns:

array of 11 parameters of the calibration matrix,

followed by error of the DLT (mean residual of the DLT transformation in units of camera coordinates).

Return type:

numpy.array, float

geometric_calibration.dlt.FixAngles(rm)[source]
geometric_calibration.dlt.Normalization(nd, x)[source]

Normalization of coordinates (centroid to the origin and mean distance of sqrt(2 or 3).

Parameters:
  • nd (int) – number of dimensions, typically 3
  • x (numpy.array) – the data to be normalized (directions at different columns and points at rows)
Returns:

the transformation matrix (translation plus

scaling), the transformed data

Return type:

numpy.array, numpy.array

geometric_calibration.dlt.VerifyAngles(outOfPlaneAngleRAD, gantryAngleRAD, inPlaneAngleRAD, referenceMatrix)[source]
geometric_calibration.dlt.decompose_camera_matrix(L, image_size, pixel_spacing)[source]
geometric_calibration.dlt.extract_param_from_matrix_Rit(camera_matrix)[source]

geometric_calibration.utils module

This module contains some utility function for image manipulation.

class geometric_calibration.utils.DraggablePoints(artists, tolerance=15)[source]

Bases: object

Draggable points on a matplotlib figure.

Returns:DraggablePoints object
Return type:DraggablePoints
__init__(artists, tolerance=15)[source]

Initialize an instance of DraggablePoints object and superimpose it on the current matplotlib Figure.

Parameters:
  • artists (list) – list of matplotlib Circles with coordinates (x,y) in pixel coordinates.
  • tolerance (int, optional) – Tolerance for mouse selection when dragging on screen. Defaults to 15.
get_coord()[source]

Obtain current coordinates (x,y) of points.

Returns:An array Nx2 containing coordinates for N point (x,y).
Return type:numpy.array
on_close(event)[source]

Event Handler for closure of figure.

Parameters:event (event) – Event that triggers the method
on_key_pressed(event)[source]

Event Handler for “Enter” key pression.

Parameters:event (event) – Event that triggers the method
on_key_released(event)[source]

Event Handler for any key released.

Parameters:event (event) – Event that triggers the method
on_motion(event)[source]

Event Handler for mouse movement during dragging of points.

Parameters:event (event) – Event that triggers the method
on_press(event)[source]

Event Handler for mouse button pression.

Parameters:event (event) – Event that triggers the method.
on_release(event)[source]

Event Handler for mouse button release.

Parameters:event (event) – Event that triggers the method
geometric_calibration.utils.create_camera_matrix(detector_orientation, sdd, sid, pixel_spacing, isocenter, proj_offset, source_offset, image_size)[source]

Generate projection matrix starting from extrinsic and intrinsic parameters (according to the rules of creation of a projection matrix).

Parameters:
  • detector_orientation (numpy.array) – Nx3 array containing rotations of the image’s plane [rot_x, rot_y, rot_z]
  • sdd (float) – Source to Detector distance
  • sid (float) – Source to Isocenter distance
  • pixel_spacing (list) – Pixel dimension in mm
  • isocenter (numpy.array) – Coordinates of isocenter
  • proj_offset (list) – Detector offset, expressed as [offset_x, offset_y]
  • source_offset (list) – Source offset, expressed as [offset_x, offset_y]
  • image_size (list) – Dimension of image
Returns:

3x4 camera matrix

Return type:

numpy.array

geometric_calibration.utils.drag_and_drop_bbs(projection, bbs_projected)[source]

Drag&Drop Routines for bbs position’s correction.

Parameters:
  • projection (str) – Path to the projection (.raw of .hnc) file
  • bbs_projected (numpy.array) – Array Nx2 with N BBs yet projected on image plane
Returns:

Array Nx2 containing the updated coordinates for N BBs

Return type:

numpy.array

geometric_calibration.utils.get_grayscale_range(img)[source]

New grayscale range for .raw or .hnc images, since original values are too bright. New range is computed between min of image and one order of magnitude less than original image. Worst case scenario [0, 6553.5] (since image is loaded as uint16).

Parameters:img (numpy.array) – Array containing the loaded .raw or .hnc image
Returns:Grayscale range for current projection
Return type:list
geometric_calibration.utils.project_camera_matrix(coord_3d, camera_matrix, image_size)[source]

Project 3D data (x,y,z) in world coordinate system to 2D (u,v) coordinate system using camera matrix computed with geometric_calibration.utils.create_camera_matrix() function.

Parameters:
  • coord_3d (numpy.array) – Nx3 array containing 3D coordinates of points (x,y,z) in world coordinate system.
  • camera_matrix (numpy.array) – 3x4 projection matrix obtained combining both extrinsic and intrinsic parameters.
  • image_size (list) – Dimension of the image
Returns:

Nx2 array containing 2D coordinates of points (u,v) projected on image plane (u,v)

Return type:

numpy.array

geometric_calibration.utils.search_bbs_centroids(img, ref_2d, search_area, image_size, mode, debug_level=0)[source]

Search bbs based on projection.

Starting from the updated coordinates, define a search area around them and identify the BBs centroid as the center of a circle or an ellipse (based on mode argument). This function automatically set as (np.nan, np.nan) the coordinates of BBs outside image space, too dark or too close to another BBs.

Parameters:
  • img (numpy.array) – Array containing the loaded .raw or .hnc file
  • ref_2d (numpy.array) – Nx2 array containing the coordinates for BBs projected on img
  • search_area (int) – Size of the region in which to search for centroids. Actual dimension of the area is a square with dimension (2* search_area,2*search_area)
  • image_size (list) – Dimension of img
  • mode (str) – Centroid search modality. It can be “circle” or “ellipse”. Ellipse is slower but provide better results in general.
  • debug_level (int, optional) – Level for debug messages, 0 means no debug messages, 1 light debug and 2 hard debug. Defaults to 0.
Returns:

Nx2 array containing coordinates for every centroids found (x,y)

Return type:

numpy.array

geometric_calibration.utils.search_bbs_centroids_hough(img, ref_2d, search_area, image_size, mode, debug_level=0)[source]

Search bbs based on projection.

Starting from the updated coordinates, define a search area around them and identify the BBs centroid as the center of a circle or an ellipse (based on mode argument). This function automatically set as (np.nan, np.nan) the coordinates of BBs outside image space, too dark or too close to another BBs.

Parameters:
  • img (numpy.array) – Array containing the loaded .raw or .hnc file
  • ref_2d (numpy.array) – Nx2 array containing the coordinates for BBs projected on img
  • search_area (int) – Size of the region in which to search for centroids. Actual dimension of the area is a square with dimension (2* search_area,2*search_area)
  • image_size (list) – Dimension of img
  • mode (str) – Centroid search modality. It can be “circle” or “ellipse”. Ellipse is slower but provide better results in general.
  • debug_level (int, optional) – Level for debug messages, 0 means no debug messages, 1 light debug and 2 hard debug. Defaults to 0.
Returns:

Nx2 array containing coordinates for every centroids found (x,y)

Return type:

numpy.array

geometric_calibration.slideshow module