Esempio n. 1
0
def update_ids_and_write(seg_map, sub_indices):
    pbar = tqdm(sub_indices, desc='Update ids to be globally unique')
    for k in pbar:
        s = seg_map[k]['input']
        seg, offset_zyx = load_inference(s)
        offset_xyz = offset_zyx[::-1]
        size_xyz = seg.shape[::-1]

        bbox = seg_map[k]['bbox']
        seg = np.transpose(seg, [2, 1, 0])
        # # make labels contiguous and unique globally but keep 0 intact
        seg = np.uint32(seg)
        zeros = seg == 0
        seg, _ = make_labels_contiguous(seg)
        seg = np.uint32(seg)
        # local_max = np.max(seg)
        seg += seg_map[k]['global_offset']
        seg[zeros] = 0

        # convert to precomputed
        precomputed_path = seg_map[k]['output']
        #seg_map[i] = (bbox, precomputed_path)
        resolution = seg_map[k]['resolution']
        chunk_size = seg_map[k]['chunk_size']
        cv = prepare_precomputed(precomputed_path, offset_xyz, size_xyz,
                                 resolution, chunk_size)
        cv[bbox] = seg
Esempio n. 2
0
def get_seg_map(input_dir,
                output_dir,
                resolution,
                chunk_size,
                sub_indices,
                post_clean_up=False):
    if not sub_indices.size:
        return {}
    get_name = lambda s: re.sub('seg-', 'precomputed-', s)
    seg_list = glob.glob(os.path.join(input_dir, 'seg*'))
    seg_list.sort()

    seg_map = dict()
    pbar = tqdm(sub_indices, desc='Generating seg map')
    for i in pbar:
        # for i in tqdm(sub_indices):
        # pbar.set_description("Generating Seg Map:")
        seg_path = seg_list[i]
        if not len(
                glob.glob(os.path.join(seg_path, '**/*.npz'), recursive=True)):
            continue
        seg, offset_zyx = load_inference(seg_path)
        offset_xyz = offset_zyx[::-1]
        size_xyz = seg.shape[::-1]

        bbox = Bbox(a=offset_xyz, b=offset_xyz + size_xyz)
        seg = np.transpose(seg, [2, 1, 0])

        # make labels contiguous and unique globally but keep 0 intact
        min_particle = 1000
        if post_clean_up:
            clean_up(seg, min_particle)
            # non_background = (seg > 0).astype(np.uint8)
            # seg = connected_components(non_background)

        seg = np.uint32(seg)
        #zeros = seg==0
        seg, _ = make_labels_contiguous(seg)
        seg = np.uint32(seg)
        local_max = np.max(seg)
        #seg += global_max
        # global_max = np.max(seg)
        # seg[zeros] = 0

        precomputed_path = os.path.join(output_dir,
                                        get_name(os.path.basename(seg_path)))
        seg_map[i] = {
            'bbox': bbox,
            'input': os.path.abspath(seg_path),
            'output': os.path.abspath(precomputed_path),
            'resolution': resolution,
            'chunk_size': chunk_size,
            'local_max': local_max
        }
    return seg_map
Esempio n. 3
0
def get_seg_map(input_dir, output_dir, resolution, chunk_size, sub_indices):
    if not sub_indices.size:
        return {}
    get_name = lambda s: re.sub('seg-', 'precomputed-', s)
    seg_list = glob.glob(os.path.join(input_dir, 'seg*'))
    seg_list.sort()

    seg_map = dict()

    pbar = tqdm(sub_indices, desc='Generating seg map')
    for i in pbar:
        # for i in tqdm(sub_indices):
        # pbar.set_description("Generating Seg Map:")
        seg_path = seg_list[i]
        seg, offset_zyx = load_inference(seg_path)
        offset_xyz = offset_zyx[::-1]
        size_xyz = seg.shape[::-1]

        bbox = Bbox(a=offset_xyz, b=offset_xyz + size_xyz)
        seg = np.transpose(seg, [2, 1, 0])

        # make labels contiguous and unique globally but keep 0 intact
        seg = np.uint32(seg)
        #zeros = seg==0
        seg, _ = make_labels_contiguous(seg)
        seg = np.uint32(seg)
        local_max = np.max(seg)
        #seg += global_max
        # global_max = np.max(seg)
        # seg[zeros] = 0

        precomputed_path = os.path.join(output_dir,
                                        get_name(os.path.basename(seg_path)))
        seg_map[i] = {
            'bbox': bbox,
            'input': os.path.abspath(seg_path),
            'output': os.path.abspath(precomputed_path),
            'resolution': resolution,
            'chunk_size': chunk_size,
            'local_max': local_max
        }
    return seg_map