88from flamingo_tools .measurements import compute_object_measures
99
1010
11- def compute_sgn_volume (cochlea , output_path , voxel_spacing , seg_name = "SGN_v2" ):
11+ def compute_volume (
12+ cochlea , output_path , voxel_spacing , seg_name = "SGN_v2" , component_list = None ,
13+ ):
1214 img_path = f"{ cochlea } /images/ome-zarr/PV.ome.zarr"
1315 seg_path = f"{ cochlea } /images/ome-zarr/{ seg_name } .ome.zarr"
1416
1517 img_path , _ = get_s3_path (img_path )
1618 seg_path , _ = get_s3_path (seg_path )
1719
20+ if component_list is None :
21+ component_list = [1 ]
22+
1823 segmentation_table_path = f"{ cochlea } /tables/{ seg_name } /default.tsv"
1924 feature_set = "morphology"
2025 compute_object_measures (
@@ -24,14 +29,14 @@ def compute_sgn_volume(cochlea, output_path, voxel_spacing, seg_name="SGN_v2"):
2429 output_table_path = output_path ,
2530 resolution = voxel_spacing ,
2631 feature_set = feature_set ,
27- component_list = [ 1 ] ,
32+ component_list = component_list ,
2833 s3_flag = True ,
2934 image_key = "s0" ,
3035 segmentation_key = "s0" ,
3136 )
3237
3338
34- def compute_volumes_flamingo ():
39+ def compute_sgn_volumes_flamingo ():
3540 output_folder = "./data/volumes_flamingo"
3641 os .makedirs (output_folder , exist_ok = True )
3742 cochleae = ["M_LR_000226_L" , "M_LR_000226_R" , "M_LR_000227_L" , "M_LR_000227_R" ]
@@ -40,10 +45,22 @@ def compute_volumes_flamingo():
4045 output_path = os .path .join (output_folder , f"{ cochlea } .tsv" )
4146 if os .path .exists (output_path ):
4247 continue
43- compute_sgn_volume (cochlea , output_path , voxel_spacing )
48+ compute_volume (cochlea , output_path , voxel_spacing )
4449
4550
46- def compute_volumes_lavision ():
51+ def compute_ihc_volumes_flamingo ():
52+ output_folder = "./data/ihc_volumes_flamingo"
53+ os .makedirs (output_folder , exist_ok = True )
54+ cochleae = ["M_LR_000226_L" , "M_LR_000226_R" , "M_LR_000227_L" , "M_LR_000227_R" ]
55+ voxel_spacing = (0.38 , 0.38 , 0.38 )
56+ for cochlea in cochleae :
57+ output_path = os .path .join (output_folder , f"{ cochlea } .tsv" )
58+ if os .path .exists (output_path ):
59+ continue
60+ compute_volume (cochlea , output_path , voxel_spacing , seg_name = "IHC_v4c" )
61+
62+
63+ def compute_sgn_volumes_lavision ():
4764 output_folder = "./data/volumes_lavision"
4865 os .makedirs (output_folder , exist_ok = True )
4966 cochleae = ["LaVision-M02" , "LaVision-M03" ]
@@ -56,10 +73,29 @@ def compute_volumes_lavision():
5673 output_path = os .path .join (output_folder , f"{ cochlea } .tsv" )
5774 if os .path .exists (output_path ):
5875 continue
59- compute_sgn_volume (cochlea , output_path , voxel_spacing , seg_name = "SGN_LOWRES-v5c" )
76+ compute_volume (cochlea , output_path , voxel_spacing , seg_name = "SGN_LOWRES-v5c" )
77+
78+
79+ def compute_ihc_volumes_lavision ():
80+ output_folder = "./data/ihc_volumes_lavision"
81+ os .makedirs (output_folder , exist_ok = True )
82+ cochleae = ["LaVision-M02" , "LaVision-M03" ]
83+ # Note: we used a wrong voxel spacing in MoBIE (1.9 micron in-plane instead of 0.76)
84+ # We solved this here in a hacky fashion by hard-coding the resolution for the volume
85+ # calculation temporariliy in the measurement function.
86+ voxel_spacing = (3.0 , 1.887779 , 1.887779 )
87+ # voxel_spacing = (3.0, 0.76, 0.76)
88+ component_lists = [[1 , 2 ], [1 ]]
89+ for cochlea , component_list in zip (cochleae , component_lists ):
90+ output_path = os .path .join (output_folder , f"{ cochlea } .tsv" )
91+ if os .path .exists (output_path ):
92+ continue
93+ compute_volume (
94+ cochlea , output_path , voxel_spacing , seg_name = "IHC_LOWRES-v3" , component_list = component_list ,
95+ )
6096
6197
62- def compare_volumes ():
98+ def compare_sgn_volumes ():
6399 cochleae_flamingo = ["M_LR_000226_L" , "M_LR_000226_R" , "M_LR_000227_L" , "M_LR_000227_R" ]
64100 cochleae_lavision = ["LaVision-M02" , "LaVision-M03" ]
65101
@@ -93,11 +129,51 @@ def compare_volumes():
93129 plt .show ()
94130
95131
132+ def compare_ihc_volumes ():
133+ cochleae_flamingo = ["M_LR_000226_L" , "M_LR_000226_R" , "M_LR_000227_L" , "M_LR_000227_R" ]
134+ cochleae_lavision = ["LaVision-M02" , "LaVision-M03" ]
135+
136+ folder_flamingo = "./data/ihc_volumes_flamingo"
137+ folder_lavision = "./data/ihc_volumes_lavision"
138+
139+ data_flamingo = []
140+ size_threshold = 30000
141+ for cochlea in cochleae_flamingo :
142+ x = pd .read_csv (os .path .join (folder_flamingo , f"{ cochlea } .tsv" ), sep = "\t " )
143+ volumes = x ["volume" ].values
144+ volumes = volumes [~ np .isnan (volumes )]
145+ volumes = volumes [volumes < size_threshold ]
146+ data_flamingo .append (volumes )
147+
148+ data_lavision = []
149+ for cochlea in cochleae_lavision :
150+ x = pd .read_csv (os .path .join (folder_lavision , f"{ cochlea } .tsv" ), sep = "\t " )
151+ volumes = x ["volume" ].values
152+ volumes = volumes [~ np .isnan (volumes )]
153+ volumes = volumes [volumes < size_threshold ]
154+ data_lavision .append (volumes )
155+
156+ fig , axes = plt .subplots (2 , sharey = True )
157+
158+ ax = axes [0 ]
159+ ax .boxplot (data_flamingo , tick_labels = cochleae_flamingo )
160+ ax .set_ylabel ("IHC Volume [µm^3]" )
161+
162+ ax = axes [1 ]
163+ ax .boxplot (data_lavision , tick_labels = cochleae_lavision )
164+ ax .set_ylabel ("IHC Volume [µm^3]" )
165+
166+ plt .show ()
167+
168+
96169def main ():
97- compute_volumes_flamingo ()
98- compute_volumes_lavision ()
170+ compute_sgn_volumes_flamingo ()
171+ compute_sgn_volumes_lavision ()
172+ # compare_sgn_volumes()
99173
100- compare_volumes ()
174+ compute_ihc_volumes_flamingo ()
175+ compute_ihc_volumes_lavision ()
176+ compare_ihc_volumes ()
101177
102178
103179if __name__ == "__main__" :
0 commit comments