@@ -12,12 +12,17 @@ def coord_from_string(center_str):
1212 return tuple ([int (c ) for c in center_str .split ("-" )])
1313
1414
15- def find_annotations (annotation_dir , cochlea ) -> dict :
16- """Create dictionary for analysis of ChReef annotations.
15+ def find_annotations (annotation_dir : str , cochlea : str ) -> dict :
16+ """Create a dictionary for the analysis of ChReef annotations.
17+
1718 Annotations should have format positive-negative_<cochlea>_crop_<coord>_allNegativeExcluded_thr<thr>.tif
1819
1920 Args:
2021 annotation_dir: Directory containing annotations.
22+ cochlea: The name of the cochlea to analyze.
23+
24+ Returns:
25+ Dictionary with information about the intensity annotations.
2126 """
2227
2328 def extract_center_string (cochlea , name ):
@@ -58,7 +63,7 @@ def get_roi(coord: tuple, roi_halo: tuple, resolution: float = 0.38) -> Tuple[in
5863 resolution: Resolution of array in µm.
5964
6065 Returns:
61- region of interest
66+ The region of interest.
6267 """
6368 coords = list (coord )
6469 # reverse dimensions for correct extraction
@@ -123,7 +128,10 @@ def find_inbetween_ids(
123128 Args:
124129 arr_negexc: Array with all negatives excluded.
125130 arr_allweak: Array with all weak positives.
126- roi_sgn: Region of interest of segmentation.
131+ roi_seg: Region of interest of segmentation.
132+
133+ Returns:
134+ A list of the ids that are in between the respective thresholds.
127135 """
128136 # negative annotation == 1, positive annotation == 2
129137 negexc_negatives = find_overlapping_masks (arr_negexc , roi_seg , label_id_base = 1 )
@@ -141,8 +149,12 @@ def get_median_intensity(file_negexc, file_allweak, center, data_seg, table):
141149
142150 roi_seg = data_seg [roi ]
143151 inbetween_ids = find_inbetween_ids (arr_negexc , arr_allweak , roi_seg )
152+ if len (inbetween_ids ) == 0 :
153+ return None
154+
144155 subset = table [table ["label_id" ].isin (inbetween_ids )]
145156 intensities = list (subset ["median" ])
157+
146158 return np .median (list (intensities ))
147159
148160
@@ -154,11 +166,14 @@ def localize_median_intensities(annotation_dir, cochlea, data_seg, table_measure
154166
155167 for center_str in annotation_dic ["center_strings" ]:
156168 center_coord = coord_from_string (center_str )
157- print (f"Getting mean intensities for { center_coord } ." )
169+ print (f"Getting median intensities for { center_coord } ." )
158170 file_pos = annotation_dic [center_str ]["file_pos" ]
159171 file_neg = annotation_dic [center_str ]["file_neg" ]
160172 median_intensity = get_median_intensity (file_neg , file_pos , center_coord , data_seg , table_measure )
161173
174+ if median_intensity is None :
175+ print (f"No inbetween IDs found for { center_str } ." )
176+
162177 annotation_dic [center_str ]["median_intensity" ] = median_intensity
163178
164179 return annotation_dic
0 commit comments