【问题标题】:Accessing LSB and MSB from Binary 8 bit image从二进制 8 位图像访问 LSB 和 MSB
【发布时间】:2021-10-28 22:35:51
【问题描述】:

我正在研究问题所在的加密:

对于图像的每个像素,将像素十进制值转换为二进制 8 位。然后将每个 8 位像素的 MSB 和 LSB 分开,并转换成十进制。

我已将图像转换为每个像素的 8 位二进制文​​件。现在我不知道如何分离 MSB 和 LSB。

这是我的代码:

#taking input image
input = cv2.imread('test.webp')
#print("before\n\n")
cv2.imshow('image before',input)


#Get input size converting to a fixed size

height, width = input.shape\[:2\]

#Desired "pixelated" size

w, h = (256, 256)

#Resize input to "pixelated" size

temp = cv2.resize(input, (w, h), interpolation=cv2.INTER_LINEAR)

print(temp)
#Initialize output image

#the converted pixed into 8bit image
output = cv2.resize(temp, (width, height), interpolation=cv2.INTER_NEAREST)
cv2.imwrite("pixelate.jpg", output)
#print(output)
#output
print('after\n\n')
cv2.imshow('image after',output)



cv2.waitKey(0)

cv2.destroyAllWindows()][1]

【问题讨论】:

    标签: python-3.x opencv image-processing binary 8-bit


    【解决方案1】:

    首先,读取图像并打印其数据类型

    img = cv2.imread('test.webp')
    print(img.dtype)
    

    如果数据类型不是 uint8,则将图像缩放到 0-255 并将其数据类型更改为 uint8

    现在,屏蔽每个像素的第一个 (LSB) 和最后一个 (MSB) 位

    import numpy as np
    mask = np.full(img.shape, 0x7E, dtype=np.uint8)
    
    res = np.bitwise_and(img, mask)
    
    import matplotlib.pyplot as plt
    plt.imshow(res)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-19
      • 2013-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-24
      • 1970-01-01
      相关资源
      最近更新 更多