如何从16位LE数据中提取这些位?
我有 16位数据在以下le位格式中:
b4 | B5 | C1 | C2 | C3 | D1 | D2 | D3
A1 | A2 | A3 | A4 | A5 | B1 | B2 | B3
每个字母代表我要提取的一个数据类别,并从中制作单独的图像。
使用此Python代码,我设法从A层创建了一个图像,但是我没有成功提取B,C和D。
# using numpy and PIL
data = np.fromfile(i, dtype=np.dtype('<u2')).reshape(size, size)
A = ((data & 31) - 1).astype('uint8')
image_A = Image.fromarray(A)
有人知道这将如何工作吗?
I've got 16 bit data in the following LE bit format:
B4 | B5 | C1 | C2 | C3 | D1 | D2 | D3
A1 | A2 | A3 | A4 | A5 | B1 | B2 | B3
Each letter represents one data category that I want to extract and make a seperate image from.
Using this python code, I managed to create an image from the A layer, but I did not succeed in extracting B, C and D.
# using numpy and PIL
data = np.fromfile(i, dtype=np.dtype('<u2')).reshape(size, size)
A = ((data & 31) - 1).astype('uint8')
image_A = Image.fromarray(A)
Does anyone know how that would work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用bitmasks的字典和一些twiddling来计算必要的变化:
Using a dictionary of bitmasks and some bit twiddling to compute the requisite shifts:
这似乎是一种简单的方法:
This seems an easy way to do it: