neuro-sam 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. neuro_sam/__init__.py +1 -0
  2. neuro_sam/brightest_path_lib/__init__.py +5 -0
  3. neuro_sam/brightest_path_lib/algorithm/__init__.py +3 -0
  4. neuro_sam/brightest_path_lib/algorithm/astar.py +586 -0
  5. neuro_sam/brightest_path_lib/algorithm/waypointastar.py +449 -0
  6. neuro_sam/brightest_path_lib/algorithm/waypointastar_speedup.py +1007 -0
  7. neuro_sam/brightest_path_lib/connected_componen.py +329 -0
  8. neuro_sam/brightest_path_lib/cost/__init__.py +8 -0
  9. neuro_sam/brightest_path_lib/cost/cost.py +33 -0
  10. neuro_sam/brightest_path_lib/cost/reciprocal.py +90 -0
  11. neuro_sam/brightest_path_lib/cost/reciprocal_transonic.py +86 -0
  12. neuro_sam/brightest_path_lib/heuristic/__init__.py +2 -0
  13. neuro_sam/brightest_path_lib/heuristic/euclidean.py +101 -0
  14. neuro_sam/brightest_path_lib/heuristic/heuristic.py +29 -0
  15. neuro_sam/brightest_path_lib/image/__init__.py +1 -0
  16. neuro_sam/brightest_path_lib/image/stats.py +197 -0
  17. neuro_sam/brightest_path_lib/input/__init__.py +1 -0
  18. neuro_sam/brightest_path_lib/input/inputs.py +14 -0
  19. neuro_sam/brightest_path_lib/node/__init__.py +2 -0
  20. neuro_sam/brightest_path_lib/node/bidirectional_node.py +240 -0
  21. neuro_sam/brightest_path_lib/node/node.py +125 -0
  22. neuro_sam/brightest_path_lib/visualization/__init__.py +4 -0
  23. neuro_sam/brightest_path_lib/visualization/flythrough.py +133 -0
  24. neuro_sam/brightest_path_lib/visualization/flythrough_all.py +394 -0
  25. neuro_sam/brightest_path_lib/visualization/tube_data.py +385 -0
  26. neuro_sam/brightest_path_lib/visualization/tube_flythrough.py +227 -0
  27. neuro_sam/napari_utils/anisotropic_scaling.py +503 -0
  28. neuro_sam/napari_utils/color_utils.py +135 -0
  29. neuro_sam/napari_utils/contrasting_color_system.py +169 -0
  30. neuro_sam/napari_utils/main_widget.py +1016 -0
  31. neuro_sam/napari_utils/path_tracing_module.py +1016 -0
  32. neuro_sam/napari_utils/punet_widget.py +424 -0
  33. neuro_sam/napari_utils/segmentation_model.py +769 -0
  34. neuro_sam/napari_utils/segmentation_module.py +649 -0
  35. neuro_sam/napari_utils/visualization_module.py +574 -0
  36. neuro_sam/plugin.py +260 -0
  37. neuro_sam/punet/__init__.py +0 -0
  38. neuro_sam/punet/deepd3_model.py +231 -0
  39. neuro_sam/punet/prob_unet_deepd3.py +431 -0
  40. neuro_sam/punet/prob_unet_with_tversky.py +375 -0
  41. neuro_sam/punet/punet_inference.py +236 -0
  42. neuro_sam/punet/run_inference.py +145 -0
  43. neuro_sam/punet/unet_blocks.py +81 -0
  44. neuro_sam/punet/utils.py +52 -0
  45. neuro_sam-0.1.0.dist-info/METADATA +269 -0
  46. neuro_sam-0.1.0.dist-info/RECORD +93 -0
  47. neuro_sam-0.1.0.dist-info/WHEEL +5 -0
  48. neuro_sam-0.1.0.dist-info/entry_points.txt +2 -0
  49. neuro_sam-0.1.0.dist-info/licenses/LICENSE +21 -0
  50. neuro_sam-0.1.0.dist-info/top_level.txt +2 -0
  51. sam2/__init__.py +11 -0
  52. sam2/automatic_mask_generator.py +454 -0
  53. sam2/benchmark.py +92 -0
  54. sam2/build_sam.py +174 -0
  55. sam2/configs/sam2/sam2_hiera_b+.yaml +113 -0
  56. sam2/configs/sam2/sam2_hiera_l.yaml +117 -0
  57. sam2/configs/sam2/sam2_hiera_s.yaml +116 -0
  58. sam2/configs/sam2/sam2_hiera_t.yaml +118 -0
  59. sam2/configs/sam2.1/sam2.1_hiera_b+.yaml +116 -0
  60. sam2/configs/sam2.1/sam2.1_hiera_l.yaml +120 -0
  61. sam2/configs/sam2.1/sam2.1_hiera_s.yaml +119 -0
  62. sam2/configs/sam2.1/sam2.1_hiera_t.yaml +121 -0
  63. sam2/configs/sam2.1_training/sam2.1_hiera_b+_MOSE_finetune.yaml +339 -0
  64. sam2/configs/train.yaml +335 -0
  65. sam2/modeling/__init__.py +5 -0
  66. sam2/modeling/backbones/__init__.py +5 -0
  67. sam2/modeling/backbones/hieradet.py +317 -0
  68. sam2/modeling/backbones/image_encoder.py +134 -0
  69. sam2/modeling/backbones/utils.py +93 -0
  70. sam2/modeling/memory_attention.py +169 -0
  71. sam2/modeling/memory_encoder.py +181 -0
  72. sam2/modeling/position_encoding.py +239 -0
  73. sam2/modeling/sam/__init__.py +5 -0
  74. sam2/modeling/sam/mask_decoder.py +295 -0
  75. sam2/modeling/sam/prompt_encoder.py +202 -0
  76. sam2/modeling/sam/transformer.py +311 -0
  77. sam2/modeling/sam2_base.py +911 -0
  78. sam2/modeling/sam2_utils.py +323 -0
  79. sam2/sam2.1_hiera_b+.yaml +116 -0
  80. sam2/sam2.1_hiera_l.yaml +120 -0
  81. sam2/sam2.1_hiera_s.yaml +119 -0
  82. sam2/sam2.1_hiera_t.yaml +121 -0
  83. sam2/sam2_hiera_b+.yaml +113 -0
  84. sam2/sam2_hiera_l.yaml +117 -0
  85. sam2/sam2_hiera_s.yaml +116 -0
  86. sam2/sam2_hiera_t.yaml +118 -0
  87. sam2/sam2_image_predictor.py +475 -0
  88. sam2/sam2_video_predictor.py +1222 -0
  89. sam2/sam2_video_predictor_legacy.py +1172 -0
  90. sam2/utils/__init__.py +5 -0
  91. sam2/utils/amg.py +348 -0
  92. sam2/utils/misc.py +349 -0
  93. sam2/utils/transforms.py +118 -0
@@ -0,0 +1,169 @@
1
+ import numpy as np
2
+ import random
3
+
4
+ class ContrastingColorManager:
5
+ """
6
+ Manages contrasting color pairs for dendrite-spine visualization.
7
+ Each dendrite gets a muted color and its spines get a contrasting neon color.
8
+ """
9
+
10
+ def __init__(self):
11
+ # Define 20 contrasting color pairs: (dendrite_color, spine_neon_color)
12
+ # Each pair is designed to be visually contrasting and complementary
13
+ self.color_pairs = [
14
+ # Pair 1: Blue dendrite -> Orange neon spine
15
+ ((0.2, 0.4, 0.8), (1.0, 0.5, 0.0)),
16
+
17
+ # Pair 2: Green dendrite -> Magenta neon spine
18
+ ((0.3, 0.7, 0.3), (1.0, 0.0, 1.0)),
19
+
20
+ # Pair 3: Purple dendrite -> Yellow neon spine
21
+ ((0.6, 0.3, 0.8), (1.0, 1.0, 0.0)),
22
+
23
+ # Pair 4: Orange dendrite -> Cyan neon spine
24
+ ((0.8, 0.5, 0.2), (0.0, 1.0, 1.0)),
25
+
26
+ # Pair 5: Teal dendrite -> Red neon spine
27
+ ((0.2, 0.7, 0.6), (1.0, 0.0, 0.0)),
28
+
29
+ # Pair 6: Pink dendrite -> Green neon spine
30
+ ((0.8, 0.4, 0.6), (0.0, 1.0, 0.0)),
31
+
32
+ # Pair 7: Yellow-green dendrite -> Purple neon spine
33
+ ((0.6, 0.8, 0.3), (0.5, 0.0, 1.0)),
34
+
35
+ # Pair 8: Coral dendrite -> Blue neon spine
36
+ ((0.8, 0.5, 0.4), (0.0, 0.5, 1.0)),
37
+
38
+ # Pair 9: Indigo dendrite -> Orange-red neon spine
39
+ ((0.3, 0.3, 0.7), (1.0, 0.3, 0.0)),
40
+
41
+ # Pair 10: Olive dendrite -> Pink neon spine
42
+ ((0.6, 0.6, 0.3), (1.0, 0.0, 0.5)),
43
+
44
+ # Pair 11: Magenta dendrite -> Lime neon spine
45
+ ((0.7, 0.3, 0.7), (0.5, 1.0, 0.0)),
46
+
47
+ # Pair 12: Cyan dendrite -> Orange neon spine
48
+ ((0.3, 0.7, 0.7), (1.0, 0.6, 0.0)),
49
+
50
+ # Pair 13: Brown dendrite -> Cyan neon spine
51
+ ((0.6, 0.4, 0.3), (0.0, 1.0, 0.8)),
52
+
53
+ # Pair 14: Lavender dendrite -> Yellow-green neon spine
54
+ ((0.7, 0.5, 0.8), (0.7, 1.0, 0.0)),
55
+
56
+ # Pair 15: Navy dendrite -> Yellow neon spine
57
+ ((0.2, 0.3, 0.6), (1.0, 0.9, 0.0)),
58
+
59
+ # Pair 16: Mint dendrite -> Magenta neon spine
60
+ ((0.4, 0.8, 0.6), (1.0, 0.2, 0.8)),
61
+
62
+ # Pair 17: Maroon dendrite -> Cyan neon spine
63
+ ((0.6, 0.2, 0.3), (0.2, 1.0, 1.0)),
64
+
65
+ # Pair 18: Gold dendrite -> Blue neon spine
66
+ ((0.8, 0.7, 0.3), (0.0, 0.3, 1.0)),
67
+
68
+ # Pair 19: Slate dendrite -> Orange neon spine
69
+ ((0.4, 0.5, 0.6), (1.0, 0.4, 0.0)),
70
+
71
+ # Pair 20: Plum dendrite -> Green neon spine
72
+ ((0.7, 0.4, 0.7), (0.2, 1.0, 0.2)),
73
+ ]
74
+
75
+ # Track which pairs have been used
76
+ self.used_pair_indices = []
77
+
78
+ # Track path assignments for consistent spine coloring
79
+ self.path_pair_assignments = {}
80
+
81
+ def get_contrasting_pair(self, path_id):
82
+ """
83
+ Get a contrasting color pair for a specific path.
84
+ Returns the same pair if called multiple times for the same path.
85
+
86
+ Args:
87
+ path_id: Unique identifier for the path
88
+
89
+ Returns:
90
+ tuple: (dendrite_color, spine_neon_color)
91
+ """
92
+ # If this path already has an assignment, return it
93
+ if path_id in self.path_pair_assignments:
94
+ pair_index = self.path_pair_assignments[path_id]
95
+ dendrite_color, spine_color = self.color_pairs[pair_index]
96
+ print(f"Returning existing color pair for path {path_id}: dendrite={dendrite_color}, spine={spine_color}")
97
+ return dendrite_color, spine_color
98
+
99
+ # Find an unused color pair
100
+ available_indices = [i for i in range(len(self.color_pairs)) if i not in self.used_pair_indices]
101
+
102
+ if available_indices:
103
+ chosen_index = random.choice(available_indices)
104
+ self.used_pair_indices.append(chosen_index)
105
+ else:
106
+ # If all pairs used, reset and start over
107
+ print("All color pairs used, resetting...")
108
+ self.used_pair_indices = []
109
+ chosen_index = random.randint(0, len(self.color_pairs) - 1)
110
+ self.used_pair_indices.append(chosen_index)
111
+
112
+ # Store the assignment for this path
113
+ self.path_pair_assignments[path_id] = chosen_index
114
+
115
+ dendrite_color, spine_color = self.color_pairs[chosen_index]
116
+
117
+ print(f"Assigned new color pair {chosen_index} to path {path_id}:")
118
+ print(f" Dendrite color: {dendrite_color}")
119
+ print(f" Spine neon color: {spine_color}")
120
+
121
+ return dendrite_color, spine_color
122
+
123
+ def get_dendrite_color(self, path_id):
124
+ """Get the dendrite color for a specific path"""
125
+ dendrite_color, _ = self.get_contrasting_pair(path_id)
126
+ return dendrite_color
127
+
128
+ def get_spine_color(self, path_id):
129
+ """Get the contrasting spine color for a specific path"""
130
+ _, spine_color = self.get_contrasting_pair(path_id)
131
+ return spine_color
132
+
133
+ def reset_assignments(self):
134
+ """Reset all color assignments (useful for new sessions)"""
135
+ self.used_pair_indices = []
136
+ self.path_pair_assignments = {}
137
+ print("Color assignments reset")
138
+
139
+ def get_pair_info(self, path_id):
140
+ """Get information about the color pair assigned to a path"""
141
+ if path_id in self.path_pair_assignments:
142
+ pair_index = self.path_pair_assignments[path_id]
143
+ dendrite_color, spine_color = self.color_pairs[pair_index]
144
+ return {
145
+ 'pair_index': pair_index,
146
+ 'dendrite_color': dendrite_color,
147
+ 'spine_color': spine_color,
148
+ 'dendrite_hex': self._rgb_to_hex(dendrite_color),
149
+ 'spine_hex': self._rgb_to_hex(spine_color)
150
+ }
151
+ return None
152
+
153
+ def _rgb_to_hex(self, rgb):
154
+ """Convert RGB tuple to hex string for display"""
155
+ r, g, b = [int(c * 255) for c in rgb]
156
+ return f"#{r:02x}{g:02x}{b:02x}"
157
+
158
+ def print_all_pairs(self):
159
+ """Print all available color pairs for reference"""
160
+ print("\nAvailable contrasting color pairs:")
161
+ print("=" * 60)
162
+ for i, (dendrite, spine) in enumerate(self.color_pairs):
163
+ dendrite_hex = self._rgb_to_hex(dendrite)
164
+ spine_hex = self._rgb_to_hex(spine)
165
+ print(f"Pair {i+1:2d}: Dendrite {dendrite_hex} -> Spine {spine_hex}")
166
+ print("=" * 60)
167
+
168
+ # Global instance
169
+ contrasting_color_manager = ContrastingColorManager()