make_timelapse_layout.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:pytorch_fnet 作者: AllenCellModeling 项目源码 文件源码
def get_img_layout(
        file_records, frames_layout, tags,
        z_slice = 15,
        spacing_v = 5,
        spacing_h = 5,
        color=255,
):
    img_layout = None
    n_rows = len(frames_layout)
    n_cols = len(tags)
    for r, idx_frame in enumerate(frames_layout):
        print('frame:', idx_frame)
        tag_path_dict = file_records.get(idx_frame)
        if tag_path_dict is None:
            print('frame {:d} did not exist. skipping....'.format(idx_frame))
            continue
        offset_r = None
        for c, tag in enumerate(tags):
            path_this_tag = tag_path_dict.get(tag)
            print('using path:', path_this_tag)
            if path_this_tag is None:
                continue
            ar = tifffile.imread(path_this_tag)
            if img_layout is None:
                shape_layout = (
                    ar.shape[1]*n_rows + (n_rows - 1)*spacing_v,
                    ar.shape[2]*n_cols + (n_cols - 1)*spacing_h,
                    3,  # assume color image
                )
                img_layout = np.ones(shape_layout, dtype=np.uint8)*color
            if offset_r is None:
                offset_r = r*(ar.shape[1] + spacing_v)
            offset_c = c*(ar.shape[2] + spacing_h)
            img = np.atleast_3d(ar[z_slice, :, :, ])
            if (r, c) == (0, 0):
                functions.add_scale_bar(img, 20, 0.3)
            img_layout[offset_r:offset_r + ar.shape[1], offset_c:offset_c + ar.shape[2], ] = img
    return img_layout
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号