@@ -119,10 +119,10 @@ def run_prediction(
119119def marker_detection (
120120 input_path : str ,
121121 input_key : str ,
122- mask_path : str ,
122+ mask_path : Optional [ str ] ,
123123 output_folder : str ,
124124 model_path : str ,
125- mask_input_key : str = "s4" ,
125+ mask_input_key : Optional [ str ] = "s4" ,
126126 max_distance : float = 20 ,
127127 resolution : float = 0.38 ,
128128):
@@ -143,13 +143,12 @@ def marker_detection(
143143 # Best approach: load IHC segmentation at a low scale level, binarize it,
144144 # dilate it and use this as mask. It can be mapped back to the full resolution
145145 # with `elf.wrapper.ResizedVolume`.
146-
147146 skip_masking = False
148147
149148 mask_preprocess_key = "mask"
150149 output_file = os .path .join (output_folder , "mask.zarr" )
151150
152- if os .path .exists (output_file ) and mask_preprocess_key in zarr .open (output_file , "r" ):
151+ if mask_path is None or ( os .path .exists (output_file ) and mask_preprocess_key in zarr .open (output_file , "r" ) ):
153152 skip_masking = True
154153
155154 if not skip_masking :
@@ -162,11 +161,6 @@ def marker_detection(
162161 f_out .create_dataset (mask_preprocess_key , data = arr_bin , compression = "gzip" )
163162
164163 # 2.) Run inference and detection of maxima.
165- # This can be taken from 'scripts/synapse_marker_detection/run_prediction.py'
166- # (And the run prediction script should then be refactored).
167-
168- block_shape = (64 , 256 , 256 )
169- halo = (16 , 64 , 64 )
170164
171165 # Skip existing prediction, which is saved in output_folder/predictions.zarr
172166 skip_prediction = False
@@ -183,11 +177,12 @@ def marker_detection(
183177 if not skip_prediction :
184178 prediction_impl (
185179 input_path , input_key , output_folder , model_path ,
186- scale = None , block_shape = block_shape , halo = halo ,
187- apply_postprocessing = False , output_channels = 1 ,
180+ scale = None , apply_postprocessing = False , output_channels = 1 ,
181+ block_shape = None , halo = None ,
188182 )
189183
190184 if not os .path .exists (detection_path ):
185+ block_shape = (64 , 256 , 256 )
191186 input_ = zarr .open (output_path , "r" )[prediction_key ]
192187 detections = find_local_maxima (
193188 input_ , block_shape = block_shape , min_distance = 2 , threshold_abs = 0.5 , verbose = True , n_threads = 16 ,
@@ -200,25 +195,25 @@ def marker_detection(
200195 detections .to_csv (detection_path , index = False , sep = "\t " )
201196
202197 else :
203- with open (detection_path , 'r' ) as f :
198+ with open (detection_path , "r" ) as f :
204199 detections = pd .read_csv (f , sep = "\t " )
205200
206201 # 3.) Map the detections to IHC and filter them based on a distance criterion.
207202 # Use the function 'map_and_filter_detections' from above.
208- input_ = read_image_data ( mask_path , input_key )
209-
210- detections_filtered = map_and_filter_detections (
211- segmentation = input_ ,
212- detections = detections ,
213- max_distance = max_distance ,
214- resolution = resolution ,
215- )
203+ if mask_path is not None :
204+ input_ = read_image_data ( mask_path , input_key )
205+ detections_filtered = map_and_filter_detections (
206+ segmentation = input_ ,
207+ detections = detections ,
208+ max_distance = max_distance ,
209+ resolution = resolution ,
210+ )
216211
217- # 4.) Add the filtered detections to MoBIE.
218- # IMPORTANT scale the coordinates with the resolution here.
219- detections_filtered ["distance_to_ihc" ] *= resolution
220- detections_filtered ["x" ] *= resolution
221- detections_filtered ["y" ] *= resolution
222- detections_filtered ["z" ] *= resolution
223- detection_path = os .path .join (output_folder , "synapse_detection_filtered.tsv" )
224- detections_filtered .to_csv (detection_path , index = False , sep = "\t " )
212+ # 4.) Add the filtered detections to MoBIE.
213+ # IMPORTANT scale the coordinates with the resolution here.
214+ detections_filtered ["distance_to_ihc" ] *= resolution
215+ detections_filtered ["x" ] *= resolution
216+ detections_filtered ["y" ] *= resolution
217+ detections_filtered ["z" ] *= resolution
218+ detection_path = os .path .join (output_folder , "synapse_detection_filtered.tsv" )
219+ detections_filtered .to_csv (detection_path , index = False , sep = "\t " )
0 commit comments