Jun*_*onS 18 python image color-depth astronomy python-imaging-library
我觉得这会更容易,但过了一段时间我终于放弃了这个,至少在几个小时......
我想从一组游戏中时光倒流的照片中重现这个尾随的星星图像.灵感来自于:

原作者使用VirtualDub拍摄的低分辨率视频帧并与imageJ结合使用.我想我可以轻松地重现这个过程,但是使用Python更具记忆意识的方法,所以我可以使用原始的高分辨率图像来获得更好的输出.
我的算法的想法很简单,一次合并两个图像,然后通过将得到的图像与下一个图像合并来迭代.这样做了几百次并且适当地称重它,以便每个图像对最终结果具有相同的贡献.
我对python很新(我不是专业的程序员,这很明显),但环顾四周我认为Python Imaging Library是非常标准的,所以我决定使用它(如果你认为的话,请纠正我)别的东西会更好).
这是我到目前为止所拥有的:
#program to blend many images into one
import os,Image
files = os.listdir("./")
finalimage=Image.open("./"+files[0]) #add the first image
for i in range(1,len(files)): #note that this will skip files[0] but go all the way to the last file
currentimage=Image.open("./"+files[i])
finalimage=Image.blend(finalimage,currentimage,1/float(i+1))#alpha is 1/i+1 so when the image is a combination of i images any adition only contributes 1/i+1.
print "\r" + str(i+1) + "/" + str(len(files)) #lousy progress indicator
finalimage.save("allblended.jpg","JPEG")
Run Code Online (Sandbox Code Playgroud)
这样做了它应该做的但是得到的图像是黑暗的,如果我只是试图增强它,很明显由于像素的值缺乏深度而导致信息丢失.(我不确定这里适当的术语是什么,颜色深度,颜色精度,像素大小).这是使用低分辨率图像的最终结果:

或者我用4k×2k分辨率(从另一组照片中)尝试:

所以,我尝试通过设置图像模式来修复它:
firstimage=Image.open("./"+files[0])
size = firstimage.size
finalimage=Image.new("I",size)
Run Code Online (Sandbox Code Playgroud)
但显然Image.blend不接受该图像模式.
ValueError:图像有错误的模式
有任何想法吗?
(我也尝试通过将它们与im.point(lambda i:i*2)组合之前将它们相乘来使图像"变暗",但结果同样糟糕)
sim*_*onb 21
这里的问题是你在每个像素的平均亮度.这似乎是明智的,但它实际上并不是你想要的 - 明亮的星星会"平均化",因为它们会在图像中移动.采取以下四个框架:
1000 0000 0000 0000
0000 0100 0000 0000
0000 0000 0010 0000
0000 0000 0000 0001
Run Code Online (Sandbox Code Playgroud)
如果你平均那些,你会得到:
0.25 0 0 0
0 0.25 0 0
0 0 0.25 0
0 0 0 0.25
Run Code Online (Sandbox Code Playgroud)
当你想要的时候:
1000
0100
0010
0001
Run Code Online (Sandbox Code Playgroud)
您可以尝试在每个像素的任何图像中看到最大值,而不是混合图像.如果你有PIL,你可以在ImageChops中尝试更轻的功能.
from PIL import ImageChops
import os, Image
files = os.listdir("./")
finalimage=Image.open("./"+files[0])
for i in range(1,len(files)):
currentimage=Image.open("./"+files[i])
finalimage=ImageChops.lighter(finalimage, currentimage)
finalimage.save("allblended.jpg","JPEG")
Run Code Online (Sandbox Code Playgroud)
这是我得到的:

编辑:我读了Reddit的帖子,看到他实际上结合了两种方法 - 一种用于星迹,另一种用于地球.这是您尝试的平均值的更好实现,具有适当的权重.我使用numpy数组作为中间存储而不是uint8 Image数组.
import os, Image
import numpy as np
files = os.listdir("./")
image=Image.open("./"+files[0])
im=np.array(image,dtype=np.float32)
for i in range(1,len(files)):
currentimage=Image.open("./"+files[i])
im += np.array(currentimage, dtype=np.float32)
im /= len(files) * 0.25 # lowered brightness, with magic factor
# clip, convert back to uint8:
final_image = Image.fromarray(np.uint8(im.clip(0,255)))
final_image.save('all_averaged.jpg', 'JPEG')
Run Code Online (Sandbox Code Playgroud)
这是图像,然后您可以将图像与前一个星迹相结合.
