@@ -46,19 +46,13 @@ def __init__(self):
4646 self ._batch_size = 1000
4747 self ._pending_count = 0
4848
49- pub .subscribe (self .compute_metrics_at_frame , "image_ready " )
49+ pub .subscribe (self .compute_metrics_at_frame , "frame_segmented " )
5050 self ._initialized = True
5151
5252 @timing_decorator ("compute_metrics_at_frame" )
5353 def compute_metrics_at_frame (
54- self , image : np .ndarray , time , position , channel , mode
54+ self , labeled_frame : np .ndarray , time , position , channel
5555 ):
56- if mode != "segmented" :
57- return
58-
59- # labeled_frame = segmentation_cache[time, position, 0] # TODO: ensure segmentationservice always returns labeled
60- labeled_frame = image
61-
6256 chan_n = ImageData .get_instance ().channel_n
6357 mcherry_frame = yfp_frame = None
6458 if chan_n == 3 :
@@ -112,18 +106,19 @@ def update_frame_metrics(self, batch_data: list):
112106 """
113107 Computes the metrics for each labeled cell from the segmentation
114108 # Uses regionprops to get geometrical features
115-
116109 # For fluorescence analysis:
117110 # Takes each segmented cell
118111 # 1. calculate physical metrics
119112 # 2. identify which fluorescence channel it is from
120113 # 3. write the actual fluorescence value
121114 """
122115
123- def calculate_cell_metrics (_frame : TLFrame ):
116+ @classmethod
117+ def calculate_cell_metrics (cls , _frame : TLFrame ):
124118 cells = regionprops (_frame .labeled_phc )
125119 batch_data = []
126120
121+ print (f"shape phc { _frame .labeled_phc .shape } mcherry { _frame .mcherry .shape } " )
127122 # Check for the fluorescence in any channel, if not, -1 and 0 fluorescence
128123 # mcherry can be None, same for yfp
129124 back_fluo_mcherry = (
@@ -141,6 +136,7 @@ def calculate_cell_metrics(_frame: TLFrame):
141136 fluorescence_level = 0.0
142137 has_fluorescence = False
143138
139+ logging .info (f"[calculate_cell_metrics] has { len (cells )} cells" )
144140 for cell in cells :
145141 cell_id = cell .label
146142
@@ -177,15 +173,21 @@ def calculate_cell_metrics(_frame: TLFrame):
177173 if has_fluorescence :
178174 # If only mcherry has fluo
179175 if back_fluo_mcherry != - 1 and back_fluo_yfp == - 1 :
180- mcherry_fluo = round (_frame .mcherry [_frame .labeled_phc == cell_id ].mean (), 4 )
176+ mcherry_fluo = round (
177+ _frame .mcherry [_frame .labeled_phc == cell_id ].mean (), 4
178+ )
181179 fluorescence_channel = 1
182180 fluorescence_level = mcherry_fluo
183181
184182 # If both have fluorescence, compare them
185183 elif back_fluo_mcherry != - 1 and back_fluo_yfp != - 1 :
186184 # Select the region corresponding to the cell in the frames
187- mcherry_fluo = round (_frame .mcherry [_frame .labeled_phc == cell_id ].mean (), 4 )
188- yfp_fluo = round (_frame .yfp [_frame .labeled_phc == cell_id ].mean (), 4 )
185+ mcherry_fluo = round (
186+ _frame .mcherry [_frame .labeled_phc == cell_id ].mean (), 4
187+ )
188+ yfp_fluo = round (
189+ _frame .yfp [_frame .labeled_phc == cell_id ].mean (), 4
190+ )
189191 if back_fluo_mcherry != - 1 and back_fluo_yfp != - 1 :
190192 if (mcherry_fluo / back_fluo_mcherry ) > (
191193 yfp_fluo / back_fluo_yfp
0 commit comments