ophth_algo_utils
Utilities for ophthalmology plugins.
Module
Functions
center_text_on_strip
def center_text_on_strip( img: Image.Image, font: ImageFont.FreeTypeFont, text_width: int, text_height: int, text: str, strip_width: int, strip_height: int, color: tuple[int, int, int] = (0, 0, 0),) ‑> PIL.Image.Image:Center text on image.
Arguments
img: The image to draw the text on.font: The font to use for the text.text_width: The width of the text.text_height: The height of the text.text: The text to draw on the image.strip_width: The width of the strip.strip_height: The height of the strip.color: The color of the text. Defaults to black.
draw_no_markers_detected_on_image_strip
def draw_no_markers_detected_on_image_strip( img: Image.Image, height: int, width: int,) ‑> PIL.Image.Image:Draw the "No markers detected" strip on the image.
Arguments
img: The image to draw the strip on.height: The height of the image.width: The width of the image.
draw_segmentation_mask_on_orig_image
def draw_segmentation_mask_on_orig_image( mask: np.ndarray, image: PIL.Image.Image, segmentation_labels: dict[str, int] = {'hypertransmission': 0, 'rpe_disruption': 1, 'is_os_disruption': 2, 'rpe_atrophy': 3, 'neurosensory_retina_atrophy': 4}, segmentation_colors: dict[str, tuple[int, int, int]] = {'hypertransmission': (255, 126, 203), 'rpe_disruption': (255, 214, 0), 'is_os_disruption': (22, 180, 242), 'rpe_atrophy': (96, 219, 0), 'neurosensory_retina_atrophy': (225, 106, 255), 'diffuse_edema': (255, 150, 3), 'serous_rpe_detachment': (77, 22, 220), 'intraretinal_cystoid_fluid': (100, 126, 62), 'subretinal_fluid': (204, 76, 45), 'subretinal_hyperreflective_material__shrm_': (225, 0, 255)}, formatted_segmentation_labels: dict[str, str] = {'hypertransmission': 'Choroidal Hypertransmission', 'rpe_disruption': 'RPE Disruption', 'is_os_disruption': 'EZ Disruption', 'rpe_atrophy': 'RPE Atrophy', 'neurosensory_retina_atrophy': 'Neurosensory Retina Atrophy', 'diffuse_edema': 'Diffuse Edema', 'serous_rpe_detachment': 'Pigment Epithelial Detachment (PED)', 'intraretinal_cystoid_fluid': 'Intraretinal fluid (IRF)', 'subretinal_fluid': 'Subretinal Fluid (SRF)', 'subretinal_hyperreflective_material__shrm_': 'Subretinal Hyperreflective Material (SHRM)'}, color_not_detected: tuple[int, int, int] = (243, 243, 247),) ‑> tuple[PIL.Image.Image, dict[str, tuple[int, int, int]]]:Draw segmentation mask on original image.
Returns tuple: Tuple containing the image with segmentation mask and a legend mapping class names to colors.
get_data_for_files
def get_data_for_files( datasource: FileSystemIterableSource, filenames: list[str], file_key_col: str = '_original_filename', use_cache: bool = True,) ‑> pandas.core.frame.DataFrame:Retrieve data from a datasource for a given list of files.
The dataframe returned will be sorted to match the ordering of the files in
filenames.
get_dataframe_iterator_from_datasource
def get_dataframe_iterator_from_datasource( datasource: BaseSource, data_splitter: Optional[DatasetSplitter] = None, use_cache: bool = True,) ‑> collections.abc.Iterable[pandas.core.frame.DataFrame]:Get dataframe iterator from datasource.
Arguments
datasource: The datasource to get the dataframe iterator from.data_splitter: The data splitter to use when getting the dataframes.use_cache: Whether to use the cache when getting the dataframes.
Returns An iterable of dataframes from the datasource.
get_imgs_with_segmentation_from_enface_slo
def get_imgs_with_segmentation_from_enface_slo( data: pd.DataFrame, enface_output: np.ndarray, slos: np.ndarray, slo_photo_location_prefixes: Optional[SLOSegmentationLocationPrefix] = None, slo_image_metadata_columns: Optional[SLOImageMetadataColumns] = None, oct_image_metadata_columns: Optional[OCTImageMetadataColumns] = None, colour: Union[str, tuple[int, int, int]] = (0, 255, 255), alpha: float = 0.75, threshold: float = 0.7,) ‑> list[PIL.Image.Image]:Get images with segmentation on SLO image from enfaces.
is_file_iterable_source
def is_file_iterable_source(datasource: BaseSource) ‑> bool:True iff datasource is a file iterable source (or subclass).
overlay_with_alpha_layer_ga_trial
def overlay_with_alpha_layer_ga_trial( img: Image.Image, overlay: np.ndarray, colour: Union[str, tuple[int, int, int]] = (255, 0, 0), alpha: float = 0.8,) ‑> PIL.Image.Image:Overlay an image with a segmentation.
overlay_with_grey_mask_ga_trial
def overlay_with_grey_mask_ga_trial( img: Image.Image, alpha: float = 0.3,) ‑> PIL.Image.Image:Overlay an image with a segmentation.
parse_mask_json
def parse_mask_json( json_data: MaskAltrisBiomarker | MaskSegmentationModel, labels: dict[str, int],) ‑> numpy.ndarray:Parse segmentation mask(s) from JSON.
Arguments
json_data: The model output JSON data for the masks.labels: The segmentation classes to generate masks for mapped to their index in the mask data.
Returns
A (num_segmentations, image_height, image_width) array where each
(image_height, image_width) subarray is the mask for a different segmentation
class.
use_default_rename_columns
def use_default_rename_columns( datasource: BaseSource, rename_columns: Optional[typing.Mapping[str, str]] = None,) ‑> Optional[Mapping[str, str]]:Sets the default columns to include based on the datasource.