Skip to content

Commit bc80409

Browse files
committed
Component labeling with multiple parameter configurations
1 parent 39adf31 commit bc80409

15 files changed

+852
-120
lines changed

flamingo_tools/segmentation/postprocessing.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ def label_components_ihc(
524524
min_size: int = 1000,
525525
min_component_length: int = 50,
526526
max_edge_distance: float = 30,
527+
min_nn_100_distance: float = None,
527528
) -> List[int]:
528529
"""Label components using graph connected components.
529530
@@ -532,6 +533,7 @@ def label_components_ihc(
532533
min_size: Minimal number of pixels for filtering small instances.
533534
min_component_length: Minimal length for filtering out connected components.
534535
max_edge_distance: Maximal distance in micrometer between points to create edges for connected components.
536+
min_nn_100_distance: Minimal value for average distance to 100 nearest neighbors.
535537
536538
Returns:
537539
List of component label for each point in dataframe. 0 - background, then in descending order of size
@@ -541,6 +543,14 @@ def label_components_ihc(
541543
entries_filtered = table[table.n_pixels < min_size]
542544
table = table[table.n_pixels >= min_size]
543545

546+
keyword = "distance_nn100"
547+
if min_nn_100_distance is not None:
548+
distance_avg = nearest_neighbor_distance(table, n_neighbors=100)
549+
table.loc[:, keyword] = list(distance_avg)
550+
entries_filtered_01 = table[table[keyword] < min_nn_100_distance]
551+
table = table[table[keyword] >= min_nn_100_distance]
552+
entries_filtered = pd.concat([entries_filtered, entries_filtered_01], ignore_index=True)
553+
544554
components = components_ihc(table, min_component_length=min_component_length,
545555
max_edge_distance=max_edge_distance)
546556

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[
2+
{
3+
"cochlea": "G_EK_000233_L",
4+
"cell_type": "ihc",
5+
"segmentation_channel": "IHC_v6",
6+
"component_list": [
7+
1
8+
],
9+
"custom_dic": {
10+
"min_size_global": 1000,
11+
"label_dicts": {
12+
"1": {
13+
"label_params": [
14+
{
15+
"max_edge_distance": 30,
16+
"min_nn_100_distance": 57
17+
},
18+
{
19+
"max_edge_distance": 25,
20+
"min_nn_100_distance": 57
21+
},
22+
{
23+
"max_edge_distance": 30,
24+
"min_nn_100_distance": 60
25+
}
26+
],
27+
"components": [
28+
[
29+
6,
30+
11
31+
],
32+
[
33+
3
34+
],
35+
[
36+
2,
37+
4,
38+
13
39+
]
40+
]
41+
}
42+
}
43+
}
44+
}
45+
]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
[
2+
{
3+
"cochlea": "G_LR_000233_R",
4+
"cell_type": "ihc",
5+
"segmentation_channel": "IHC_v6",
6+
"component_list": [
7+
1
8+
],
9+
"custom_dic": {
10+
"min_size_global": 10000,
11+
"label_dicts": {
12+
"1": {
13+
"label_params": [
14+
{
15+
"min_size": 10000,
16+
"max_edge_distance": 25,
17+
"min_component_length": 200,
18+
"min_nn_100_distance": 75
19+
},
20+
{
21+
"min_size": 10000,
22+
"max_edge_distance": 23,
23+
"min_component_length": 50,
24+
"min_nn_100_distance": 70
25+
},
26+
{
27+
"min_size": 12000,
28+
"max_edge_distance": 23,
29+
"min_component_length": 20,
30+
"min_nn_100_distance": 65
31+
}
32+
],
33+
"components": [
34+
[
35+
1,
36+
2,
37+
5
38+
],
39+
[
40+
8,
41+
9
42+
],
43+
[
44+
2,
45+
7,
46+
8,
47+
11,
48+
58
49+
]
50+
]
51+
}
52+
}
53+
}
54+
}
55+
]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[
2+
{
3+
"cochlea": "LaVision-M02",
4+
"cell_type": "ihc",
5+
"segmentation_channel": "IHC_LOWRES-v3",
6+
"component_list": [
7+
1
8+
],
9+
"custom_dic": {
10+
"min_size_global": 500,
11+
"label_dicts": {
12+
"1": {
13+
"label_params": [
14+
{
15+
"min_size": 100,
16+
"max_edge_distance": 39,
17+
"min_component_length": 2
18+
}
19+
],
20+
"components": [
21+
[
22+
1,
23+
3,
24+
6,
25+
8,
26+
22,
27+
24,
28+
67,
29+
68,
30+
132,
31+
133
32+
]
33+
]
34+
}
35+
}
36+
}
37+
}
38+
]
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
[
2+
{
3+
"cochlea": "LaVision-M04",
4+
"cell_type": "ihc",
5+
"segmentation_channel": "IHC_LOWRES-v3",
6+
"component_list": [
7+
1
8+
],
9+
"custom_dic": {
10+
"min_size_global": 500,
11+
"missing_ids": [
12+
428,
13+
650,
14+
1128,
15+
2121,
16+
4653,
17+
121,
18+
122,
19+
123,
20+
735,
21+
745,
22+
725,
23+
925,
24+
4285,
25+
4286,
26+
4282,
27+
4412,
28+
4413,
29+
4405,
30+
4402,
31+
4464,
32+
4513,
33+
4511,
34+
4512,
35+
4510
36+
],
37+
"label_dicts": {
38+
"1": {
39+
"label_params": [
40+
{
41+
"min_size": 500,
42+
"max_edge_distance": 55,
43+
"min_component_length": 10
44+
}
45+
],
46+
"components": [
47+
[
48+
2,
49+
23,
50+
58,
51+
1,
52+
5,
53+
9,
54+
37,
55+
13,
56+
7
57+
]
58+
]
59+
}
60+
}
61+
}
62+
}
63+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[
2+
{
3+
"cochlea": "LaVision-Mar05",
4+
"cell_type": "ihc",
5+
"segmentation_channel": "IHC_LOWRES-v3",
6+
"component_list": [
7+
1,
8+
2,
9+
3,
10+
11,
11+
5,
12+
9
13+
],
14+
"min_size": 20,
15+
"max_edge_distance": 50,
16+
"min_component_length": 20
17+
}
18+
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"cochlea": "LaVision-OTOF23R",
4+
"cell_type": "ihc",
5+
"segmentation_channel": "IHC_LOWRES-v3",
6+
"component_list": [
7+
4,
8+
18,
9+
7
10+
],
11+
"min_size": 20,
12+
"max_edge_distance": 50,
13+
"min_component_length": 20
14+
}
15+
]
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
[
2+
{
3+
"cochlea": "LaVision-OTOF25R",
4+
"cell_type": "ihc",
5+
"segmentation_channel": "IHC_LOWRES-v3",
6+
"component_list": [
7+
1,
8+
2
9+
],
10+
"custom_dic": {
11+
"min_size_global": 500,
12+
"missing_ids": [
13+
4800,
14+
4832
15+
],
16+
"label_dicts": {
17+
"1": {
18+
"label_params": [
19+
{
20+
"min_size": 500,
21+
"max_edge_distance": 65,
22+
"min_component_length": 5
23+
},
24+
{
25+
"min_size": 400,
26+
"max_edge_distance": 45,
27+
"min_component_length": 5
28+
},
29+
{
30+
"min_size": 400,
31+
"max_edge_distance": 40,
32+
"min_component_length": 5
33+
},
34+
{
35+
"min_size": 400,
36+
"max_edge_distance": 50,
37+
"min_component_length": 5
38+
}
39+
],
40+
"components": [
41+
[
42+
18,
43+
22
44+
],
45+
[
46+
1,
47+
45,
48+
83
49+
],
50+
[
51+
18,
52+
39
53+
],
54+
[
55+
77,
56+
66
57+
]
58+
]
59+
},
60+
"2": {
61+
"label_params": [
62+
{
63+
"min_size": 500,
64+
"max_edge_distance": 65,
65+
"min_component_length": 5
66+
}
67+
],
68+
"components": [
69+
[
70+
16
71+
]
72+
]
73+
}
74+
}
75+
}
76+
}
77+
]

0 commit comments

Comments
 (0)