Created
January 27, 2021 21:33
-
-
Save possan/ebd331f73ee775d6d11e04e28fb13c17 to your computer and use it in GitHub Desktop.
polar movie converter
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
# Converts polar image to small led filmstrip | |
# Convert movie to images: ffmpeg -i a1-2.mov frames/outb-%4d.jpg | |
INPUTFORMAT = 'frames/oute-{:04d}.jpg' | |
FRAMES = 2000 | |
OUTPUT = 'a5-filmstrip.png' | |
OUTPUT2 = '.hitarea.png' | |
SAMPLES = 30 | |
import math | |
from PIL import Image | |
outimg = Image.new('RGB', (33, FRAMES)) | |
outpx = outimg.load() | |
columns = [] | |
fn = INPUTFORMAT.format(1) | |
img = Image.open(fn) | |
px = img.load() | |
size = img.width | |
center = size / 2 | |
radii = size * 0.495 | |
radiidiff = size * 0.003 | |
angdiff = 0.25 # in pixel space +/- 0.4 1/33rd pixels | |
del(img) | |
outimg2 = Image.new('RGB', (size, size)) | |
outpx2 = outimg2.load() | |
for j in range(33): | |
a = (j + (33.0 / 2.0)) | |
samples = [] | |
for d in range(SAMPLES): | |
da = d * math.pi / (SAMPLES / 2.0) | |
a2 = a + angdiff * math.sin(da) | |
x = center + radii * math.cos(a2 * math.pi / (33.0 / 2.0) ) | |
y = center + radii * math.sin(a2 * math.pi / (33.0 / 2.0) ) | |
x2 = round(x) # + ra * math.cos(a2)) | |
y2 = round(y) # + ra * math.sin(a2)) | |
if x2 < 0: | |
x2 = 0 | |
if y2 < 0: | |
y2 = 0 | |
if x2 > size - 1: | |
x2 = size - 1 | |
if y2 > size - 1: | |
y2 = size - 1 | |
samples.append((x2, y2)) | |
outpx2[y2, x2] = 0xffffff | |
print (j, samples) | |
columns.append(samples) | |
outimg2.save(OUTPUT2, 'PNG') | |
# print (columns) | |
for k in range(FRAMES): | |
fn = INPUTFORMAT.format(k + 1) | |
print ("Load frame %d: %s" % (k, fn)) | |
img = Image.open(fn) | |
px = img.load() | |
for j in range(33): | |
psum = (0, 0, 0) | |
for d in range(SAMPLES): | |
x2, y2 = columns[j][d] | |
p = px[y2, x2] | |
psum = ( | |
psum[0] + p[0], | |
psum[1] + p[1], | |
psum[2] + p[2], | |
) | |
psum = ( | |
round(psum[0] / SAMPLES), | |
round(psum[1] / SAMPLES), | |
round(psum[2] / SAMPLES), | |
) | |
outpx[j, k] = psum | |
outimg.save(OUTPUT, 'PNG') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment