1+ # /// script
2+ # requires-python = ">=3.13"
3+ # dependencies = [
4+ # "click",
5+ # "girder-client",
6+ # "numpy",
7+ # "pillow",
8+ # "pycocotools",
9+ # "scikit-image",
10+ # "setuptools"
11+ # ]
12+ # ///
113import json
214import random
315import numpy as np
1931SHAPE_SIZE = (100 , 100 ) # width, height of shape
2032
2133CONFIG = [
22- {'track_number' : 0 , 'num_frames' : 500 , 'mask_type' : 'pentagon' , 'motion_type' : 'circle' },
23- {'track_number' : 1 , 'num_frames' : 300 , 'mask_type' : 'circle' , 'motion_type' : 'bounce' },
24- {'track_number' : 2 , 'num_frames' : 200 , 'mask_type' : 'rectangle' , 'motion_type' : 'circle' },
34+ {'track_number' : 2 , 'num_frames' : 500 , 'mask_type' : 'pentagon' , 'motion_type' : 'circle' },
35+ {'track_number' : 3 , 'num_frames' : 300 , 'mask_type' : 'circle' , 'motion_type' : 'bounce' },
36+ {'track_number' : 4 , 'num_frames' : 200 , 'mask_type' : 'rectangle' , 'motion_type' : 'circle' },
2537]
2638
2739
@@ -99,10 +111,10 @@ def bouncing_motion(num_frames, img_size, shape_size):
99111@click .option ('--upload' , is_flag = True , help = 'Upload generated masks to Girder.' )
100112def generate_tracks (upload ):
101113 output_masks_exist = os .path .exists ('outputMasks' )
102- rle_json_exist = os .path .exists ('RLEMask .json' )
114+ rle_json_exist = os .path .exists ('RLE_MASKS .json' )
103115
104116 if output_masks_exist and rle_json_exist :
105- print ("Found existing outputMasks folder and RLEMask .json. Skipping generation." )
117+ print ("Found existing outputMasks folder and RLE_MASKS .json. Skipping generation." )
106118 else :
107119 print ("Generating new masks and JSON files..." )
108120
@@ -173,7 +185,7 @@ def generate_tracks(upload):
173185 }
174186
175187 if OUTPUT_MASKS :
176- output_dir = os .path .join ('outputMasks' , f'{ track_id } ' )
188+ output_dir = os .path .join ('outputMasks/masks ' , f'{ track_id } ' )
177189 os .makedirs (output_dir , exist_ok = True )
178190
179191 alpha_channel = (mask > 0 ).astype (np .uint8 ) * 255
@@ -187,18 +199,22 @@ def generate_tracks(upload):
187199
188200 track_data ['tracks' ][str (track_id )] = track
189201
190- with open ('trackJSON .json' , 'w' ) as f :
202+ with open ('TrackJSON .json' , 'w' ) as f :
191203 json .dump (track_data , f , indent = 2 )
192204
193- with open ('RLEMask.json' , 'w' ) as f :
194- json .dump (mask_data , f , indent = 2 )
195205
196206 with open ('RLE_MASKS.json' , 'w' ) as f :
197207 json .dump (rle_masks_json , f , indent = 2 )
198208
199- print ('Generated trackJSON.json, RLEMask .json, RLE_MASKS.json' , end = '' )
209+ print ('Generated TrackJSON .json, RLE_MASKS.json' , end = '' )
200210 if OUTPUT_MASKS :
201211 print (', and PNG masks in outputMasks/' )
212+ with open ('outputMasks/masks/TrackJSON.json' , 'w' ) as f :
213+ json .dump (track_data , f , indent = 2 )
214+
215+ with open ('outputMasks/masks/RLE_MASKS.json' , 'w' ) as f :
216+ json .dump (rle_masks_json , f , indent = 2 )
217+
202218 else :
203219 print ('.' )
204220
0 commit comments