32 lines
747 B
Python
32 lines
747 B
Python
|
# -*- coding:utf-8 -*-
|
||
|
# @Author len
|
||
|
# @Create 2023/10/11 10:25
|
||
|
|
||
|
from PIL import Image
|
||
|
import numpy as np
|
||
|
|
||
|
import numpy as np
|
||
|
from PIL import Image
|
||
|
|
||
|
# 读取RGB565格式的二进制文件
|
||
|
with open('result0.bin', 'rb') as f:
|
||
|
image_data = f.read()
|
||
|
|
||
|
# 计算图像尺寸
|
||
|
width = 800
|
||
|
height = 480
|
||
|
|
||
|
# 将二进制数据转换为NumPy数组
|
||
|
image_array = np.frombuffer(image_data, dtype=np.uint16)
|
||
|
|
||
|
# 重塑数组形状
|
||
|
image_array = image_array.reshape((height, width))
|
||
|
|
||
|
# 转换为RGB888格式的图像数据
|
||
|
image_array = np.asarray(np.unpackbits(image_array[:, :, None].astype(np.uint8), axis=2), dtype=np.uint8) * 255
|
||
|
|
||
|
# 创建PIL图像对象
|
||
|
image = Image.fromarray(image_array, 'RGB')
|
||
|
|
||
|
# 将图像保存为JPEG文件
|
||
|
image.save('output.jpg')
|