@@ -37,12 +37,12 @@ def patching(WSI_object, **kwargs):
3737 start_time = time .time ()
3838
3939 # Patch
40- file_path = WSI_object .process_contours (** kwargs )
40+ file_path , attr_dict = WSI_object .process_contours (** kwargs )
4141
4242
4343 ### Stop Patch Timer
4444 patch_time_elapsed = time .time () - start_time
45- return file_path , patch_time_elapsed
45+ return file_path , patch_time_elapsed , attr_dict
4646
4747
4848def seg_and_patch (source , save_dir , patch_save_dir , mask_save_dir , stitch_save_dir ,
@@ -52,7 +52,8 @@ def seg_and_patch(source, save_dir, patch_save_dir, mask_save_dir, stitch_save_d
5252 filter_params = {'a_t' :100 , 'a_h' : 16 , 'max_n_holes' :8 },
5353 vis_params = {'vis_level' : - 1 , 'line_thickness' : 500 },
5454 patch_params = {'use_padding' : True , 'contour_fn' : 'four_pt' },
55- patch_level = 0 ,
55+ magnification = None ,
56+ patch_level = 0 , custom_downsample = 1 ,
5657 use_default_params = False ,
5758 seg = False , save_mask = True ,
5859 stitch = False ,
@@ -195,9 +196,23 @@ def seg_and_patch(source, save_dir, patch_save_dir, mask_save_dir, stitch_save_d
195196
196197 patch_time_elapsed = - 1 # Default time
197198 if patch :
198- current_patch_params .update ({'patch_level' : patch_level , 'patch_size' : patch_size , 'step_size' : step_size ,
199+ if magnification :
200+ if WSI_object .max_objective_magnification is None :
201+ df .loc [idx , 'status' ] = 'WSI do not has the attribute of objective magnification.'
202+ print ('WSI do not has the attribute of objective magnification.' )
203+ continue
204+ patch_level , custom_downsample = WSI_object .getPatchLevel (magnification )
205+ if isinstance (patch_level , dict ):
206+ df .loc [idx , 'status' ] = patch_level ['error' ]
207+ print (patch_level ['error' ])
208+ continue
209+ current_patch_params .update ({'patch_level' : patch_level , 'patch_size' : patch_size ,
210+ 'step_size' : step_size , 'custom_downsample' : custom_downsample ,
199211 'save_path' : patch_save_dir })
200- file_path , patch_time_elapsed = patching (WSI_object = WSI_object , ** current_patch_params ,)
212+ file_path , patch_time_elapsed , attr_dict = patching (WSI_object = WSI_object , ** current_patch_params )
213+ print (attr_dict )
214+ for key in ['patch_level' , 'target_patch_size' , 'target_step_size' ,'patch_size' , 'step_size' , 'custom_downsample' ]:
215+ df .loc [i , key ] = attr_dict [key ]
201216
202217 stitch_time_elapsed = - 1
203218 if stitch :
@@ -242,6 +257,8 @@ def seg_and_patch(source, save_dir, patch_save_dir, mask_save_dir, stitch_save_d
242257 help = 'directory to save processed data' )
243258parser .add_argument ('--preset' , default = None , type = str ,
244259 help = 'predefined profile of default segmentation and filter parameters (.csv)' )
260+ parser .add_argument ('--magnification' , type = int , default = None ,
261+ help = 'objective magnification at which to patch. When it is not None, the patch_level does not work.' )
245262parser .add_argument ('--patch_level' , type = int , default = 0 ,
246263 help = 'downsample level at which to patch' )
247264parser .add_argument ('--process_list' , type = str , default = None ,
@@ -306,6 +323,6 @@ def seg_and_patch(source, save_dir, patch_save_dir, mask_save_dir, stitch_save_d
306323 seg_times , patch_times = seg_and_patch (** directories , ** parameters ,
307324 patch_size = args .patch_size , step_size = args .step_size ,
308325 seg = args .seg , use_default_params = False , save_mask = True ,
309- stitch = args .stitch ,
326+ stitch = args .stitch , magnification = args . magnification ,
310327 patch_level = args .patch_level , patch = args .patch ,
311328 process_list = process_list , auto_skip = args .no_auto_skip )
0 commit comments