apply_coordinate_offset

apply_coordinate_offset(data_array, offset, key, keys_to_shift=('centroid', 'box', 'contours'), *, verbose=True)[source]

Apply Coordinate offset “info_dict” output.

Applies a 2D translation (dx, dy) to various geometric data structures stored within a NumPy object array.

The function handles three specific structures: - Centroids: Shape (2,) -> [x, y] - Boxes: Shape (4,) -> [xmin, ymin, xmax, ymax] - Contours: Shape (N, 2) -> [[x1, y1], [x2, y2], …]

Parameters:
  • data_array (np.ndarray) – A NumPy array with dtype=object, where each element is a NumPy array representing a centroid, box, or contour.

  • offset (tuple[int, int] | np.ndarray | list[int]) – A sequence of two values representing the [dx, dy] translation.

  • key (str) – Current key in the “info_dict” to process.

  • keys_to_shift (list (str)) – Tuple of keys to shift in x, y. Keys such as “probability” and “type” do not need to be shifted. Default is [“centroid”, “box”, “contours”].

  • verbose (bool) – Whether to display progress bar.

Returns:

A new NumPy array of dtype=object containing the translated geometric data, preserving the original internal data types

(e.g., int32).

Return type:

np.ndarray