Skip to content

Instantly share code, notes, and snippets.

@LongHairedHacker
Last active Feb 4, 2018
Embed
What would you like to do?
NOAA APT Splitter PoC
#!/usr/bin/env python3
from PIL import Image
import matplotlib.pyplot as plt
WEDGE_WIDTH = 45
WEDGE_END = 1040
WEDGE_START = WEDGE_END - WEDGE_WIDTH
THRESHOLD = -100
def average_wedgeline(img, y):
avg = 0
for cx in range(WEDGE_START, WEDGE_END):
avg += float(img.getpixel((cx, y))) / WEDGE_WIDTH
return avg
def read_wedges(img):
wedges = []
for wedge_id in range(0, 16):
avg = 0
for y in range(wedge_id * 8, (wedge_id + 1) * 8):
avg += average_wedgeline(img, y) / 8.0
wedges += [avg]
return wedges
def adjust_brightness(zero_mod, max_mod, value):
dyn_range = max_mod - zero_mod
value = int(((value - zero_mod) / dyn_range) * 255)
value = max(0, value)
value = min(255, value)
return value
def main():
full_image = Image.open("example.png")
w, h = full_image.size
last_wedge = average_wedgeline(full_image, 0)
averages = [last_wedge]
diffs = [0]
frame_count = 0
for y in range(1, h):
cur_wedge = average_wedgeline(full_image, y)
averages += [cur_wedge]
diff = cur_wedge - last_wedge
diffs += [diff]
if diff < THRESHOLD:
start = y - 64
end = y + 64
print("Potential Frame: %d to %d" % (start, end))
frame = full_image.crop(box=(0, start, w, end))
wedges = read_wedges(frame)
zero_mod = wedges[8]
max_mod = wedges[7]
wedges = [adjust_brightness(zero_mod, max_mod, wedge) for wedge in wedges]
print("\tWedges: %s" % repr(wedges))
pixels = frame.load()
for x in range(0, 2080):
for y in range(0, 128):
pixels[x,y] = adjust_brightness(zero_mod, max_mod, pixels[x,y])
frame.save("frame%d.png" % frame_count)
frame_count += 1
last_wedge = cur_wedge
plt.plot(averages)
plt.plot(diffs)
plt.show()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment