Created
February 11, 2023 22:11
-
-
Save samjsharpe/4f8d2eda8c5b874d4b548848779da871 to your computer and use it in GitHub Desktop.
extract images from IRG file
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
from re import A | |
from PIL import Image, ImageDraw | |
width = 180 | |
height = 240 | |
diff_start=0x80 | |
first_array_start = diff_start | |
first_array_end = diff_start + width * height - 1 | |
second_array_start = diff_start + width * height | |
second_array_end = second_array_start + 2 * width * height | |
file = open("230119180929.irg", mode='br') | |
data = file.read() | |
fir = data[first_array_start:first_array_end] | |
sus_temp = data[second_array_start:second_array_end] | |
sus = [sus_temp[x] for x in range(0, len(sus_temp), 2)] | |
diff = [i - j for i, j in zip(fir, sus)] | |
sum = [i + j for i, j in zip(fir, sus)] | |
def draw(array, name): | |
im = Image.new("L", (width, height)) | |
draw = ImageDraw.Draw(im) | |
for (i, offset) in enumerate(range(0, len(array))): | |
x = i % width | |
y = i // width | |
value = array[offset] | |
draw.point((x, y), value) | |
im.save(f"{name}.png") | |
draw(fir, "first") | |
draw(sus, "second") | |
draw(diff, "diff") | |
draw(sum, "sum") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This results in 4 images, the first and second in the input file, plus the difference and the sum (showing that they are not exactly the same values.