1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
   | import numpy as np import matplotlib.pyplot as plt
  def convert_binary_to_hex(binary_string):     decimal_value = int(binary_string, 2)     hex_string = format(decimal_value, '02X')     return hex_string
  def main():     with open('Raine1.txt', 'r') as file1, open('Gideon1.txt', 'r') as file2, open('Beryl1.txt', 'r') as file3:         binary1 = file1.read()         binary2 = file2.read()         binary3 = file3.read()
          hex_colors = []         for i in range(0, len(binary1), 8):             r = convert_binary_to_hex(binary1[i:i+8])             g = convert_binary_to_hex(binary2[i:i+8])             b = convert_binary_to_hex(binary3[i:i+8])             hex_colors.append((r+g+b))             #print(hex_colors)             #这里可以打印出来一些RGB像素数据来判断进制转换是否正确                  # 将16进制颜色转换为RGB格式     rgb_colors = [tuple(int(hex[i:i + 2], 16) for i in (0, 2, 4)) for hex in hex_colors]
      # 创建一个数组以存储像素值     image_array = np.array([rgb_colors], dtype=np.uint8)
      # 调整数组形状以匹配图像尺寸     #这里我发现的图片尺寸是384*576     image_array = image_array.reshape(384, 576, 3)
      # 绘制图像     plt.imshow(image_array)     plt.axis('off')
      # 保存图像为文件     plt.savefig('output_image.png')
 
  if __name__ == "__main__":     main()
 
  |