deepblink.data module

List of functions to handle data including converting matrices <-> coordinates.

deepblink.data.absolute_coordinate(coord_spot: Tuple[numpy.float32, numpy.float32], coord_cell: Tuple[numpy.float32, numpy.float32], cell_size: int = 4) → Tuple[numpy.float32, numpy.float32][source]

Return the absolute image coordinate from a relative cell coordinate.

Parameters:
  • coord_spot – Relative spot coordinate in format (r, c).
  • coord_cell – Top-left coordinate of the cell.
  • cell_size – Size of one cell in a grid.
Returns:

Absolute coordinate.

deepblink.data.get_coordinate_list(matrix: numpy.ndarray, image_size: int = 512, probability: float = 0.5) → numpy.ndarray[source]

Convert the prediction matrix into a list of coordinates.

NOTE - plt.scatter uses the x, y system. Therefore any plots must be inverted by assigning x=c, y=r!

Parameters:
  • matrix – Matrix representation of spot coordinates.
  • image_size – Default image size the grid was layed on.
  • probability – Cutoff value to round model prediction probability.
Returns:

Array of r, c coordinates with the shape (n, 2).

deepblink.data.get_prediction_matrix(coords: numpy.ndarray, image_size: int, cell_size: int = 4, size_c: int = None) → numpy.ndarray[source]

Return np.ndarray of shape (n, n, 3): p, r, c format for each cell.

Parameters:
  • coords – List of coordinates in r, c format with shape (n, 2).
  • image_size – Size of the image from which List of coordinates are extracted.
  • cell_size – Size of one grid cell inside the matrix. A cell_size of 2 means that one cell corresponds to 2 pixels in the original image.
  • size_c – If empty, assumes a squared image. Else the length of the r axis.
Returns:

The prediction matrix as numpy array of shape (n, n, 3) – p, r, c format for each cell.

deepblink.data.next_multiple(x: int, k: int = 512) → int[source]

Calculate x’s closest higher multiple of base k.

deepblink.data.next_power(x: int, k: int = 2) → int[source]

Calculate x’s next higher power of k.

deepblink.data.normalize_image(image: numpy.ndarray) → numpy.ndarray[source]

Normalize image to a mean of zero and a standard deviation of one.