对图像施加人工过曝处理

def gaussian2D(shape, sigma=1):
    """
    compute gaussian
    """
    m, n = [(ss - 1.) / 2. for ss in shape]
    y, x = np.ogrid[-m:m + 1, -n:n + 1]

    h = np.exp(-(x * x + y * y) / (2 * sigma * sigma))  # 离原点越近越大
    h[h < np.finfo(h.dtype).eps * h.max()] = 0  # np.finfo(h.dtype).eps是指非负的最小值
    h = h * 255
    h = np.stack((h,) * 3, axis = -1).astype(int)
    return h


def draw_umich_gaussian(heatmap, center):
    """
    draw gaussian in heatmap
    """
    heatmap = np.int64(heatmap)
    height, width = heatmap.shape[0:2]
    radius = 100
    diameter = 2 * radius + 1  # radius
    # compute gaussian value
    gaussian = gaussian2D((diameter, diameter), sigma=diameter / 6) 
    plt.imshow(gaussian)
    plt.show()
    x, y = int(center[0]), int(center[1])  # 获得整形的中点坐标
    #gaussian[:, :, 0] = gaussian[:, :, 0] * (255 - heatmap[x, y, 0])
    #gaussian[:, :, 1] = gaussian[:, :, 1] * (255 - heatmap[x, y, 1])
    #gaussian[:, :, 2] = gaussian[:, :, 2] * (255 - heatmap[x, y, 2])
    #gaussian.astype(int)

    # get gaussian map pos
    left, right = min(x, radius), min(height - x, radius + 1)  # 如果xy落在heatmap的边上,离边的距离小于r,就要限制一下防止越界
    top, bottom = min(y, radius), min(width - y, radius + 1)

    # get masked heatmap pos
    masked_heatmap = heatmap[x - left:x + right, y - top:y + bottom, :]  # 得到我们要替换heatmap的位置
    masked_gaussian = gaussian[radius - left:radius + right, radius - top:radius + bottom, :]  # 得到可用高斯的范围

    heatmap[x - left:x + right, y - top:y + bottom, :] = masked_heatmap + masked_gaussian
    print(masked_gaussian.dtype, masked_heatmap.dtype, heatmap.dtype)
    #heatmap[heatmap > 255] = 255
    heatmap = np.clip(heatmap, 0, 255)
    heatmap = np.uint8(heatmap)
    return heatmap


def over_pixel(img, labels, ovpix_prob):
    img_w, img_h, _ = img.shape
    label = random.choice(labels)
    if random.random() < ovpix_prob:
        start_x = int(np.random.uniform(label[1] , label[3]))
        start_y = int(np.random.uniform(label[0] , label[2]))
        img = draw_umich_gaussian(img, (start_x, start_y))
        cv2.imshow("over_image", img)
        cv2.waitKey()
    return img

  • 8
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CVplayer111

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值