utils_pro.py 文件源码

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

项目:cav_gcnn 作者: myinxd 项目源码 文件源码
def img_recover(data, label, imgsize=(200, 200), px_over=5):
    """Recover the image after classification.

    Inputs
    ======
    data: np.ndarray
        the splitted samples data of the observation
    label: np.ndarray
        the estimated labels
    imgsize: tuple
        shape of the image
    px_over: integer
        the overlapped pixels

    Output
    ======
    img: np.ndarray
        the recovered image
    """
    # Init
    img = np.zeros(imgsize, dtype=bool)

    # Get params
    numsamples, boxsize = data.shape
    boxsize = int(np.sqrt(boxsize))
    # Number of boxes
    px_diff = boxsize - px_over
    box_rows = int(np.round((imgsize[0] - boxsize - 1) / px_diff)) + 1
    box_cols = int(np.round((imgsize[1] - boxsize - 1) / px_diff)) + 1

    # recover
    for i in range(box_rows):
        for j in range(box_cols):
            if label[i*box_rows+j] == 1:
                label_temp = True
            else:
                label_temp = False
            img[i * px_diff:i * px_diff + boxsize,
                j * px_diff:j * px_diff + boxsize] += label_temp

    return img.astype(int)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号