Sampling from Segmented Images

cell_boundaries(imarray: ndarray[Any, dtype[int64]], n_sample: int, background: int = 0, discard_cells_with_holes: bool = False, only_longest: bool = False) List[Tuple[int, ndarray[Any, dtype[float64]]]]

Sample n coordinates from the boundary of each cell in a segmented image, skipping cells that touch the border of the image

Parameters
  • imarray (ndarray[Any, dtype[int64]]) – 2D segmented image where the pixels belonging to different cells have different values

  • n_sample (int) – number of pixel coordinates to sample from boundary of each cell

  • background (int) – value of background pixels, this will not be saved as a boundary

  • discard_cells_with_holes (bool) – if discard_cells_with_holes is true, we discard any cells with more than one boundary (e.g., an annulus) with a warning. Else, the behavior is determined by only_longest.

  • only_longest (bool) – if discard_cells_with_holes is true, only_longest is irrelevant. Otherwise, this determines whether we sample points from only the longest boundary (presumably the exterior) or from all boundaries, exterior and interior.

Returns

list of float numpy arrays of shape (n_sample, 2) containing points sampled from the contours.

Return type

List[Tuple[int, ndarray[Any, dtype[float64]]]]

compute_icdm_all(infolder: str, out_csv: str, n_sample: int, num_processes: int = 8, background: int = 0, discard_cells_with_holes: bool = False, only_longest: bool = False) None

Read in each segmented image in a folder (assumed to be .tif), save n pixel coordinates sampled from the boundary of each cell in the segmented image, skipping cells that touch the border of the image.

Parameters
  • infolder (str) – path to folder containing .tif files.

  • out_csv (str) – path to csv file to save cell boundaries.

  • n_sample (int) – number of pixel coordinates to sample from boundary of each cell

  • discard_cells_with_holes (bool) – if discard_cells_with_holes is true, we discard any cells with more than one boundary (e.g., an annulus) with a warning. Else, the behavior is determined by only_longest.

  • background (int) – value which characterizes the color of the background pixels, this will not be saved as a boundary

  • only_longest (bool) – if discard_cells_with_holes is true, only_longest is irrelevant. Otherwise, this determines whether we sample points from only the longest boundary (presumably the exterior) or from all boundaries, exterior and interior.

  • num_processes (int) – How many threads to run while sampling.

Returns

None (writes to file)

Return type

None