Skip to content

Instantly share code, notes, and snippets.

@thibthibaut
Last active January 17, 2020 15:39
Show Gist options
  • Save thibthibaut/e6fb0f8e2b60961bc0f30710e80ada4a to your computer and use it in GitHub Desktop.
Save thibthibaut/e6fb0f8e2b60961bc0f30710e80ada4a to your computer and use it in GitHub Desktop.
# %% Load libraries
import numpy as np
import matplotlib.pyplot as plt
# For RGB888
w, h = (640, 480)
img = np.fromfile('img.bin', dtype=np.uint8)
img = img.reshape((h, w, 3))
# For RGB565
def rgb5to8(img):
h, w = img.shape[0], img.shape[1]
out = np.zeros((h, w, 3), dtype=np.uint8)
for i, pix in enumerate(img.flatten()):
out[i//w][i % w][0] = ((0x1f & (pix >> 11)) * 527 + 23) >> 6
out[i//w][i % w][1] = ((0x3f & (pix >> 5)) * 259 + 33) >> 6
out[i//w][i % w][2] = ((0x1f & pix) * 527 + 23) >> 6
return out
# RGB565 Case
imSize = (240, 320)
img = np.fromfile('./rgb565.bin', dtype=np.uint16).reshape(imSize)
# print(img.shape)
img = rgb5to8(img)
plt.imshow(img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment