【问题标题】:How to embed an image to a cover image by selecting random pixels in cover image?如何通过选择封面图像中的随机像素将图像嵌入封面图像?
【发布时间】:2021-06-26 17:50:30
【问题描述】:
def embedding(hideImagePath,coverImagePath):
    img1 = cv2.imread(coverImagePath, 0)
    img2 = cv2.imread(hideImagePath, 0)
    for i in range (img2.shape[0]):
        for j in range(img2.shape[1]):
                #convert pixel to binary 
                pixels_cover = format(img1[i][j], '08b')
                pixels_hide = format(img2[i][j], '08b')
                #replace the last 2 LSB from cover image with 2 MSB from hide image
                stegoImage = pixels_cover[:6] + pixels_hide[:2]
                img1[i][j] = int(stegoImage, 2)
    cv2.imwrite('StegoImage.png', img1)

以上是我到目前为止所做的代码。它按顺序隐藏封面图像中的像素,但我需要它通过从封面图像中选择随机像素来将图像隐藏到封面图像。

【问题讨论】:

    标签: python steganography


    【解决方案1】:

    从概念上讲,您希望生成所有像素坐标并以一种确定的方式对其进行打乱,以便提取知道在哪里查找。

    import itertools as it
    import random
    
    def permute_indices(shape, password):
        indices = list(it.product(*map(range, shape)))
        random.seed(password)
        random.shuffle(indices)
        return iter(indices)
    

    例如

    >>> idx = permute_indices((600, 800), 'hunter2')
    >>> for _ in range(5):
        print(next(idx))
    
        
    (411, 359)
    (379, 680)
    (110, 612)
    (246, 388)
    (232, 605)
    

    对代码的调整

    def embedding(hideImagePath, coverImagePath, password):
        img1 = cv2.imread(coverImagePath, 0)
        img2 = cv2.imread(hideImagePath, 0)
        indices = permute_indices(img1.shape, password)
        for i in range (img2.shape[0]):
            for j in range(img2.shape[1]):
                    x, y = next(indices)
                    #convert pixel to binary
                    pixels_cover = format(img1[x][y], '08b')
                    pixels_hide = format(img2[i][j], '08b')
                    #replace the last 2 LSB from cover image with 2 MSB from hide image
                    stegoImage = pixels_cover[:6] + pixels_hide[:2]
                    img1[x][y] = int(stegoImage, 2)
        cv2.imwrite('StegoImage.png', img1)
    

    【讨论】:

      猜你喜欢
      • 2021-07-09
      • 1970-01-01
      • 2013-07-21
      • 1970-01-01
      • 2022-10-08
      • 2017-12-17
      • 1970-01-01
      • 1970-01-01
      • 2014-08-07
      相关资源
      最近更新 更多