blur.py 文件源码

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

项目:hamming-stego 作者: DakotaNelson 项目源码 文件源码
def randomize(img, noise_level=.03):
    """ given an array, randomizes the values in that array

        noise_level [0,1] controls the overall likelihood of a bit being
        flipped. This overall level is then multiplied by the levels variable,
        which modifies the noise level for the various significant bit values
        (i.e. it makes it so that less significant bits are more likely to be
        flipped, which is accurate)
    """
    levels = [.005, .01, .05, .10, .15, .25, .35, .45]
    # more or less randomly chosen modifiers for each bit significance level

    for val in np.nditer(img, op_flags=['readwrite']):
        xor_val = 0
        for level in levels:
            if random.random() < level * noise_level:
                xor_val = (xor_val << 1) | 1
            else:
                xor_val = (xor_val << 1) | 0
        #print('{:08b}'.format(int(xor_val)))
        val[...] = val ^ xor_val

    return img
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号