转换为0和1的图像

时间:2019-05-24 22:45:26

标签: python python-3.x

我有一张已转换为位图的图像,它输出了一串数字。现在,我想获取该数字字符串(每个数字代表8位)并将其转换为长度为八倍的新字符串,并且仅包含0和1。

这是我用来转换图像的代码。

with open("monoT.bmp", "rb") as image:
  f = image.read()
  b = bytearray(f)

c=[i for i in b] 
print(c)

这是它的输出:

[66, 77, 94, 2, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 40, 0, 0, 0, 51, 0, 0, 0, 68, 0,
 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 32, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 255, 255, 255, 224,
 0, 255, 255, 255, 255, 255, 255, 224, 0, 255, 255, 255, 255, 255, 255, 224, 0,
 255, 255, 255, 255, 255, 255, 224, 0, 255, 255, 255, 255, 255, 255, 224, 0,
 255, 255, 255, 255, 255, 255, 224, 0, 255, 255, 255, 255, 255, 255, 224, 0,
 255, 255, 255, 255, 255, 255, 224, 0, 255, 255, 255, 255, 255, 255, 224, 0,
 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255,
 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255,
 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0,
 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127,
 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255,
 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255,
 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224,
 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0,
 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255,
 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255,
 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0,
 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127,
 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255,
 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255,
 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224,
 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0,
 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255,
 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255,
 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0,
 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127,
 255, 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255,
 255, 224, 0, 255, 255, 0, 127, 255, 255, 224, 0, 255, 255, 0, 127, 255, 255,
 224, 0, 192, 0, 0, 0, 1, 255, 224, 0, 192, 0, 0, 0, 1, 255, 224, 0, 192, 0,
 0, 0, 1, 255, 224, 0, 192, 0, 0, 0, 1, 255, 224, 0, 192, 0, 0, 0, 1, 255,
 224, 0, 192, 0, 0, 0, 1, 255, 224, 0, 192, 0, 0, 0, 1, 255, 224, 0, 255,
 255, 255, 255, 255, 255, 224, 0, 255, 255, 255, 255, 255, 255, 224, 0, 255,
 255, 255, 255, 255, 255, 224, 0, 255, 255, 255, 255, 255, 255, 224, 0, 255,
 255, 255, 255, 255, 255, 224, 0]

所以我需要将其转换为0和1,它的长度是它的八倍。该图像也似乎具有标题,该字符串的前62个条目。有没有办法在没有标题的情况下进行打印?

0 个答案:

没有答案