Last active
September 22, 2019 00:00
-
-
Save sagz/3fb2af73da82663f39ba3b2f5d123abb to your computer and use it in GitHub Desktop.
For CopyCat dataset from Kshitish's disk - Python script to convert .bytes to png
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python script to convert .bytes to png | |
import io | |
from PIL import Image | |
import numpy as np | |
import sys | |
from array import array | |
def readimage(path): | |
count = os.stat(path).st_size / 2 | |
with open(path, "rb") as f: | |
return bytearray(f.read()) | |
path = '/o/projects/copycat/kinect-conversion-test092119'+'/Alligator_behind_black_wall_color_257.bytes' | |
savepath = '/o/projects/copycat/kinect-conversion-test092119'+'/Alligator_behind_black_wall_color_257.png' | |
byteFile = readimage(path) | |
print(len(byteFile)) | |
new_image = Image.frombytes("RGBA", (1920, 1080), bytes(byteFile)) | |
new_image = new_image.convert("RGBA") | |
data = np.array(new_image) | |
red, green, blue, alpha = data.T | |
data = np.array([blue, green, red, alpha]) | |
data = data.transpose() | |
new_image = Image.fromarray(data) | |
# image = Image.open(io.BytesIO(byteFile)) | |
new_image.save(savepath) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment