tumourkit.utils.preprocessing.create_geojson
- tumourkit.utils.preprocessing.create_geojson(contours: List[Tuple[int, int]], num_classes: int | None = 2) List[Dict[str, Any]]
Converts a list of contours and their labels to a list of dictionaries containing GeoJSON-formatted data.
- Parameters:
contours (List[Tuple[int, int]]) – A list of pairs (contour, label) where contour is a list of points starting and finishing in the same point and label is an integer representing the class of the cell (1: non-tumour, 2: tumour).
num_classes (Optional[int]) – The number of classes in the data. Defaults to 2.
- Returns:
A list of dictionaries with the GeoJSON format of QuPath.
- Return type:
List[Dict[str, Any]]
This function converts a list of contours and their labels to a list of dictionaries containing GeoJSON-formatted data. The function expects the contours to be a list of pairs (contour, label), where contour is a list of points starting and finishing in the same point, and label is an integer representing the class of the cell (1: non-tumour, 2: tumour).
The function returns a list of dictionaries with the GeoJSON format of QuPath. The number of classes can be specified with the num_classes parameter. By default, it is set to 2, but it can be set to any integer greater than or equal to 1.
The function uses a list of labels and colour codes to create the classification data for the output dictionaries. The labels and colour codes are stored in the label_dict and colour_dict lists, respectively. The label_dict list contains the names of the labels and the colour_dict list contains the corresponding RGB colour codes for each label. By default, the label_dict list contains the values [“background”, “non-tumour”, “tumour”, “segmented”] and the colour_dict list contains the value [-9408287, -9408287, -9408287, -9408287]. If the num_classes parameter is set to a value other than 2, the label_dict list is updated to contain the values [“background”, “Class1”, “Class2”, …, “ClassN”], where N is the number of classes, and the colour_dict list is updated to contain the value [-9408287, …, -9408287] where the length of the list is N+1. Although this list is superfluous and not used by QuPath.
Each dictionary in the output list represents a cell contour and contains a Polygon object with the contour points, a classification object with the name and colour of the label, and a boolean indicating whether the object is locked. The dictionary is in the format expected by QuPath for reading annotations.