def parse_operation_sequence(op_name, resol, return_str=False, stack=None): inverse = op_name.startswith('-') if inverse: op_name = op_name[1:] #op = load_ini(os.path.join(DATA_ROOTDIR, 'CSHL_data_processed', stack, 'operation_configs', op_name + '.ini')) op_path = os.path.join(DATA_ROOTDIR, 'CSHL_data_processed', stack, 'operation_configs', op_name + '.ini') op = load_ini(op_path) #print op if op is None: raise Exception("Cannot load %s.ini" % op_name) if 'operation_sequence' in op: # composite operation assert not inverse, "Inverse composite operation is not implemented." op_seq = list( chain(*map( lambda o: parse_operation_sequence( o, resol=resol, return_str=return_str, stack=stack), op['operation_sequence']))) assert all( [ op_seq[i][3] == op_seq[i + 1][2] for i in range(0, len(op_seq) - 1) ] ), "In and out domains are not consistent along the composite operation chain. %s" % [ (o[2], o[3]) for o in op_seq ] else: # single operation op_arr = convert_operation_to_arr(op, resol=resol, inverse=inverse, return_str=return_str, stack=stack) if inverse: op_seq = [(op['type'], op_arr, op['dest_prep_id'], op['base_prep_id'])] else: op_seq = [(op['type'], op_arr, op['base_prep_id'], op['dest_prep_id'])] #print op_seq return op_seq
from utilities.data_manager_v2 import DataManager from utilities.utilities2015 import load_ini, create_parent_dir_if_not_exists parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description='Rescale image') parser.add_argument("input_spec", type=str, help="Input image name") parser.add_argument('out_resol', type=str, help='') parser.add_argument("-f", "--rescale_factor", type=float, help="Rescale factor") parser.add_argument("-W", "--width", type=int, help="Width") parser.add_argument("-H", "--height", type=int, help="Height") args = parser.parse_args() input_spec = load_ini(args.input_spec) stack = input_spec['stack'] prep_id = input_spec['prep_id'] if prep_id == 'None': prep_id = None resol = input_spec['resol'] version = input_spec['version'] if version == 'None': version = None image_name_list = input_spec['image_name_list'] if image_name_list == 'all': image_name_list = DataManager.load_sorted_filenames(stack=stack)[0].keys() from PIL import Image
parser.add_argument("--op", type=str, help="Op id of warp") parser.add_argument("--prep_id", type=str, help="Prep ID of the warp") parser.add_argument("--elastix_output_dir", type=str, help="Elastix-generated pairwise transform output dir") parser.add_argument("--custom_output_dir", type=str, help="User-corrected pairwise transform output dir") parser.add_argument("--anchor_img_name", type=str, help="Anchor image name") parser.add_argument("--out", type=str, help="csv, composed transforms for each image to anchor") args = parser.parse_args() input_spec = load_ini(args.input_spec) image_name_list = input_spec['image_name_list'] if image_name_list == 'all': #image_name_list = DataManager.load_sorted_filenames(stack=stack)[0].keys() image_name_list = map( lambda x: x[0], sorted(DataManager.load_sorted_filenames( stack=input_spec['stack'])[0].items(), key=lambda x: x[1])) #op = load_ini(os.path.join(DATA_ROOTDIR, 'CSHL_data_processed', input_spec['stack'], 'operation_configs', args.op + '.ini')) op = load_ini( os.path.join(DATA_ROOTDIR, 'CSHL_data_processed', input_spec['stack'], 'operation_configs', args.op + '.ini')) assert op['type'] == 'warp', "Op type must be warp." assert op['base_prep_id'] == input_spec[
from utilities.data_manager_v2 import DataManager parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description= """Align consecutive images. Possible bad alignment pairs are written into a separate file. Usage 1: align_compose.py in.ini --op from_none_to_aligned """) parser.add_argument("input_spec", type=str, help="input specifier. ini") parser.add_argument("--op", type=str, help="operation id") args = parser.parse_args() print('args', args) input_spec = load_ini(args.input_spec) stack = input_spec['stack'] sqlController = SqlController() fileLocationManager = FileLocationManager(stack) execute_command('python align_v3.py %s --op %s' % (args.input_spec, args.op)) # execute_command('python compose_v3.py %s --op %s' % (args.input_spec, args.op)) #image_name_list = input_spec['image_name_list'] image_name_list = sqlController.get_image_list(stack, 'destination') #if image_name_list == 'all': # #image_name_list = DataManager.load_sorted_filenames(stack=stack)[0].keys() # image_name_list = map(lambda x: x[0], sorted(DataManager.load_sorted_filenames(stack=input_spec['stack'])[0].items(), key=lambda x: x[1])) #op = load_ini(os.path.join(DATA_ROOTDIR, 'CSHL_data_processed', input_spec['stack'], 'operation_configs', args.op + '.ini')) op = load_ini(
simple_global_bbox_fp = os.path.join(DATA_ROOTDIR, 'CSHL_simple_global_registration', stack + '_registered_atlas_structures_wrt_wholebrainXYcropped_xysecTwoCorners.json') # Try to load the XY cropping boxes for each structure, generated from Global Alignment try: registered_atlas_structures_wrt_wholebrainXYcropped_xysecTwoCorners = load_json( simple_global_bbox_fp ) print('Global Alignment files loaded!') # Make cropping box cover the entire image if Global Alignment was not run except: print('Global Alignment files not found, not using a cropping box') registered_atlas_structures_wrt_wholebrainXYcropped_xysecTwoCorners = {} all_structures_total = structures_sided_sorted_by_size op_path = os.path.join( DATA_ROOTDIR,'CSHL_data_processed',stack, 'operation_configs', 'from_padded_to_brainstem.ini') op = load_ini(op_path) img_x_len = 32*(op['caudal_limit'] - op['rostral_limit']) img_y_len = 32*(op['ventral_limit'] - op['dorsal_limit']) num_images = 1 + valid_secmax - valid_secmin for structure in all_structures_total: registered_atlas_structures_wrt_wholebrainXYcropped_xysecTwoCorners[structure] = [[0, 0, 0], [img_x_len, img_y_len, num_images]] ######## Identify ROI based on simple global alignment ######## print('\n\nIdentifying ROIs based on simple global alignment:') print('____________________________________________________\n') registered_atlas_structures_wrt_wholebrainXYcropped_bboxes_perSection = defaultdict(dict) section_margin_um = 400.