代码拉取完成,页面将自动刷新
import numpy as np
import cmath
import cv2
def bin2dec(bits, width, msb='left'):
chunks = np.reshape(bits, (-1, width))
decVals = np.zeros(chunks.shape[0])
for cdx, chunk in enumerate(chunks):
for i, j in enumerate(chunk):
if msb == 'right':
decVals[cdx] += j << i
else:
decVals[cdx] += j << (len(chunk)-i-1)
return decVals
def dec2bin(vals, width, msb='left'):
if msb == 'left':
bits = [np.binary_repr(val, width) for val in vals]
else:
bits = [np.binary_repr(val, width)[::-1] for val in vals]
bits = ''.join(bits)
bits = np.array([int(b) for b in bits])
return bits
def polar2rect(r, phi):
phi = cmath.pi * phi / 180.0
return cmath.rect(r,phi)
def img2bits(img):
shape = img.shape
bits = dec2bin(img.flatten(), 8)
return bits, shape
def bits2img(bitChunks, shape):
vals = bin2dec(bitChunks, 8)
img = vals.reshape(shape)
img = np.uint8(img)
return img
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。