tumourkit.preprocessing.centroidspng2csv.centroidspng2csv

tumourkit.preprocessing.centroidspng2csv.centroidspng2csv(centroids_file: ndarray, png_file: ndarray) DataFrame

Converts a PNG file with cell labels and a CSV file with cell centroids into a CSV file associating each cell label with the closest centroid.

Parameters:
  • centroids_file (np.ndarray) – A NumPy array with three columns, representing the X and Y coordinates and class of each centroid.

  • png_file (np.ndarray) – A NumPy array with the same dimensions as the corresponding image file, where each pixel is labeled with an integer representing the cell it belongs to.

Returns:

A Pandas DataFrame with two columns: the first represents the cell ID from the PNG file, and the second represents the class of the closest centroid from the CSV file.

Return type:

pd.DataFrame

This function first generates a k-d tree from the centroids in the centroids_file array. For each centroid in the png_file array, the function finds the closest centroid in the centroids_file array using the k-d tree. It then associates the cell label from the PNG file with the class of the closest centroid in a list. Finally, the function returns a Pandas DataFrame containing the list of cell IDs and centroid classes.