Skip to content

Commit 15c4003

Browse files
committed
Updated image channels for object measure
1 parent 34b4156 commit 15c4003

File tree

12 files changed

+39
-26
lines changed

12 files changed

+39
-26
lines changed

flamingo_tools/segmentation/chreef_utils.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import math
23
import multiprocessing as mp
34
from concurrent import futures
45
from typing import List, Tuple
@@ -8,7 +9,7 @@
89
from tqdm import tqdm
910

1011

11-
def find_annotations(annotation_dir) -> dict:
12+
def find_annotations(annotation_dir, cochleae=None) -> dict:
1213
"""Create dictionary for analysis of ChReef annotations.
1314
Annotations should have format positive-negative_<cochlea>_crop_<coord>_allNegativeExcluded_thr<thr>.tif
1415
@@ -30,16 +31,18 @@ def extract_cochlea_str(name):
3031
return cochlea
3132

3233
file_names = [entry.name for entry in os.scandir(annotation_dir)]
33-
cochleae = list(set([extract_cochlea_str(file_name) for file_name in file_names]))
34+
if cochleae is None:
35+
cochleae = list(set([extract_cochlea_str(file_name) for file_name in file_names]))
36+
3437
annotation_dic = {}
3538
for cochlea in cochleae:
3639
cochlea_files = [entry.name for entry in os.scandir(annotation_dir) if cochlea in entry.name]
3740
dic = {"cochlea": cochlea}
3841
dic["cochlea_files"] = cochlea_files
3942
center_crops = list(set([extract_center_crop(cochlea, name=file_name) for file_name in cochlea_files]))
4043
dic["center_coords"] = center_crops
41-
dic["center_coords_str"] = [("-").join([str(c).zfill(4) for center_crop in center_crops for c in center_crop])]
42-
for center_str in dic["center_coords_str"]:
44+
dic["center_str"] = [("-").join([str(c).zfill(4) for center_crop in center_crops for c in center_crop])]
45+
for center_str in dic["center_str"]:
4346
file_neg = [c for c in cochlea_files if all(x in c for x in [cochlea, center_str, "NegativeExcluded"])][0]
4447
file_pos = [c for c in cochlea_files if all(x in c for x in [cochlea, center_str, "WeakPositive"])][0]
4548
dic[center_str] = {"file_neg": file_neg, "file_pos": file_pos}
@@ -141,3 +144,24 @@ def get_median_intensity(file_negexc, file_allweak, center, data_seg, table):
141144
inbetween_ids = find_inbetween_ids(arr_negexc, arr_allweak, roi_seg)
142145
intensities = table.loc[table["label_id"].isin(inbetween_ids), table["mean"]]
143146
return np.median(list(intensities))
147+
148+
149+
def localize_median_intensities(annotation_dir, cochlea, data_seg, table_measure, table_block=None):
150+
annotation_dic = find_annotations(annotation_dir, cochleae=[cochlea])
151+
for key in annotation_dic.keys():
152+
dic = annotation_dic[key]
153+
for center_coord, center_str in zip(dic["center_coords"], dic["center_str"]):
154+
file_pos = dic[center_str["file_pos"]]
155+
file_neg = dic[center_str["file_neg"]]
156+
median_intensity = get_median_intensity(file_neg, file_pos, center_coord, data_seg, table_measure)
157+
158+
annotation_dic[key][center_str]["median_intensity"] = median_intensity
159+
if table_block is not None:
160+
block_centers = table_block["crop_centers"]
161+
for num, block_center in enumerate(block_centers):
162+
dist = math.dist(tuple(block_centers), center_coord)
163+
if dist < 5:
164+
annotation_dic[key][center_str]["block_index"] = num
165+
annotation_dic[key][center_str]["block_center"] = block_center
166+
167+
return annotation_dic[cochlea]

reproducibility/object_measures/ChReef_MLR143L.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{
33
"cochlea": "M_LR_000143_L",
44
"image_channel": [
5-
"PV",
65
"GFP"
76
],
87
"segmentation_channel": "SGN_v2",
@@ -11,4 +10,4 @@
1110
1
1211
]
1312
}
14-
]
13+
]

reproducibility/object_measures/ChReef_MLR144L.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{
33
"cochlea": "M_LR_000144_L",
44
"image_channel": [
5-
"PV",
65
"GFP"
76
],
87
"segmentation_channel": "SGN_v2",
@@ -11,4 +10,4 @@
1110
1
1211
]
1312
}
14-
]
13+
]

reproducibility/object_measures/ChReef_MLR144R.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{
33
"cochlea": "M_LR_000144_R",
44
"image_channel": [
5-
"PV",
65
"GFP"
76
],
87
"segmentation_channel": "SGN_v2",
@@ -11,4 +10,4 @@
1110
1
1211
]
1312
}
14-
]
13+
]

reproducibility/object_measures/ChReef_MLR145L.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{
33
"cochlea": "M_LR_000145_L",
44
"image_channel": [
5-
"PV",
65
"GFP"
76
],
87
"segmentation_channel": "SGN_v2",
@@ -11,4 +10,4 @@
1110
1
1211
]
1312
}
14-
]
13+
]

reproducibility/object_measures/ChReef_MLR145R.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{
33
"cochlea": "M_LR_000145_R",
44
"image_channel": [
5-
"PV",
65
"GFP"
76
],
87
"segmentation_channel": "SGN_v2",
@@ -11,4 +10,4 @@
1110
1
1211
]
1312
}
14-
]
13+
]

reproducibility/object_measures/ChReef_MLR153L.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{
33
"cochlea": "M_LR_000153_L",
44
"image_channel": [
5-
"PV",
65
"GFP"
76
],
87
"segmentation_channel": "SGN_v2",
@@ -13,4 +12,4 @@
1312
3
1413
]
1514
}
16-
]
15+
]

reproducibility/object_measures/ChReef_MLR153R.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{
33
"cochlea": "M_LR_000153_R",
44
"image_channel": [
5-
"PV",
65
"GFP"
76
],
87
"segmentation_channel": "SGN_v2",
@@ -11,4 +10,4 @@
1110
1
1211
]
1312
}
14-
]
13+
]

reproducibility/object_measures/ChReef_MLR155L.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{
33
"cochlea": "M_LR_000155_L",
44
"image_channel": [
5-
"PV",
65
"GFP"
76
],
87
"segmentation_channel": "SGN_v2",
@@ -11,4 +10,4 @@
1110
1
1211
]
1312
}
14-
]
13+
]

reproducibility/object_measures/ChReef_MLR155R.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{
33
"cochlea": "M_LR_000155_R",
44
"image_channel": [
5-
"PV",
65
"GFP"
76
],
87
"segmentation_channel": "SGN_v2",
@@ -11,4 +10,4 @@
1110
1
1211
]
1312
}
14-
]
13+
]

0 commit comments

Comments
 (0)