1 Star 0 Fork 0

zhoub86/PAPRnet

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
utils.py 1011 Bytes
一键复制 编辑 原始数据 按行查看 历史
Shahruk Hossain 提交于 2019-04-13 09:52 . initial commit
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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhoub86/PAPRnet.git
git@gitee.com:zhoub86/PAPRnet.git
zhoub86
PAPRnet
PAPRnet
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385