Exemple #1
0
def run_aligner(args):

    # Make a list of all the relevant sections
    with open(args.sections_list_file, 'rt') as in_f:
        secs_ts_fnames = in_f.readlines()
    secs_ts_fnames = [fname.strip() for fname in secs_ts_fnames]

    # Make sure the tilespecs exist
    all_files_exist = True
    for sec_ts_fname in secs_ts_fnames:
        if not os.path.exists(sec_ts_fname):
            print("Cannot find tilespec file: {}".format(sec_ts_fname))
            all_files_exist = False

    if not all_files_exist:
        print("One or more tilespecs could not be found, exiting!")
        return

    out_folder = './output_aligned_ECS_test9_cropped'
    conf_fname = '../../conf/conf_example.yaml'

    conf = StackAligner.load_conf_from_file(args.conf_fname)
    logger.report_event("Loading sections", log_level=logging.INFO)
    sections = []
    # TODO - Should be done in a parallel fashion
    for ts_fname in secs_ts_fnames:
        with open(ts_fname, 'rt') as in_f:
            tilespec = ujson.load(in_f)

        wafer_num = int(os.path.basename(ts_fname).split('_')[0].split('W')[1])
        sec_num = int(
            os.path.basename(ts_fname).split('.')[0].split('_')[1].split('Sec')
            [1])
        sections.append(
            Section.create_from_tilespec(tilespec,
                                         wafer_section=(wafer_num, sec_num)))

    logger.report_event("Initializing aligner", log_level=logging.INFO)
    aligner = StackAligner(conf)
    logger.report_event("Aligning sections", log_level=logging.INFO)
    aligner.align_sections(
        sections)  # will align and update the section tiles' transformations

    del aligner

    logger.end_process('main ending', rh_logger.ExitCode(0))
        with in_fs.open(fs.path.basename(in_ts_fname), 'rt') as in_f:
            in_ts = ujson.load(in_f)

        wafer_num = int(
            fs.path.basename(in_ts_fname).split('_')[0].split('W')[1])
        sec_num = int(
            fs.path.basename(in_ts_fname).split('.')[0].split('_')[1].split(
                'Sec')[1])
        section = Section.create_from_tilespec(in_ts,
                                               wafer_section=(wafer_num,
                                                              sec_num))
        stitcher.stitch_section(section)

        # Save the tilespec
        section.save_as_json(out_ts_fname)


#         out_tilespec = section.tilespec
#         import json
#         with open(out_ts_fname, 'wt') as out_f:
#             json.dump(out_tilespec, out_f, sort_keys=True, indent=4)

    del stitcher

if __name__ == '__main__':
    args = parse_args()

    logger.start_process('main', '2d_stitcher_driver.py', [args])
    run_stitcher(args)
    logger.end_process('main ending', rh_logger.ExitCode(0))
        'tile_files_or_dirs',
        metavar='tile_files_or_dirs',
        type=str,
        nargs='+',
        help=
        'a list of json files that need to be normalized or a directories of json files'
    )
    parser.add_argument('-o',
                        '--output_dir',
                        type=str,
                        help='an output directory (default: ./after_norm)',
                        default='./after_norm')
    parser.add_argument('-p',
                        '--processes_num',
                        type=int,
                        help='number of processes (default: 1)',
                        default=1)

    args = parser.parse_args()

    logger.start_process('normalize_coordinates', 'normalize_coordinates.py',
                         [args.tile_files_or_dirs, args.output_dir])
    pool = mp.Pool(processes=args.processes_num)

    normalize_coordinates(args.tile_files_or_dirs, args.output_dir, pool)

    pool.close()
    pool.join()

    logger.end_process('normalize_coordinates', rh_logger.ExitCode(0))
Exemple #4
0
        return aligner.align_imgs(imgs)


if __name__ == '__main__':
    imgs_dir = '/n/coxfs01/paragt/Adi/R0/images_margin'
    conf_fname = '../conf_example.yaml'
    out_path = './output_imgs'
    processes_num = 8

    logger.start_process('main', 'aligner.py',
                         [imgs_dir, conf_fname, out_path, processes_num])
    conf = StackAligner.load_conf_from_file(conf_fname)
    transforms = StackAligner.align_img_files(imgs_dir, conf, processes_num)

    # Save the transforms to a temp output folder
    if not os.path.exists(out_path):
        os.makedirs(out_path)

    print('Writing output to: {}'.format(out_path))
    img_fnames, imgs = StackAligner.read_imgs(imgs_dir)
    for img_fname, img, transform in zip(img_fnames, imgs, transforms):
        # assumption: the output image shape will be the same as the input image
        out_fname = os.path.join(out_path, os.path.basename(img_fname))
        img_transformed = cv2.warpAffine(img,
                                         transform[:2, :],
                                         (img.shape[1], img.shape[0]),
                                         flags=cv2.INTER_AREA)
        cv2.imwrite(out_fname, img_transformed)

    logger.end_process('align_imgs ending', rh_logger.ExitCode(0))