I'm trying to make some strar trail pictures in python, and I seem to be missing some basic understanding of how the image library works. Because in my head, it should work fine to just add all the frames together and divide it by the number of frames.
However that gives a completely black picture, while just adding them gives the picture below.
Code:
import Image
import numpy as num
data = num.genfromtxt('list.txt',dtype='str')
pic = 0
for i in range(len(data)):
im1=Image.open(data[i])
pic1=num.array(im1)
pic = pic + pic1
print(i)
pic = pic/2
im = Image.fromarray(pic)
im.save("pytrail.jpg")
print(i/len(data))
Result:
Now if I grab some code from the net:
from PIL import ImageChops
import os, Image
data = num.genfromtxt('list.txt',dtype='str')
finalimage=Image.open(data[0])
for i in range(1,len(data)):
currentimage=Image.open(data[i])
finalimage=ImageChops.lighter(finalimage, currentimage)
finalimage.save("allblended.jpg","JPEG")
I get this:
But I'm not sure how this is different.
lighter
ImageChops.lighter(image1, image2) ⇒ image
Compares the two images, pixel by pixel, and returns a new image containing the lighter values.
out = max(image1, image2)
I get that this seeks out the lighter pixels, but that should be a form of averaging right? Is there a way to make my way work? (even if it means reduced brightness)
Not really averaging. Let's see a quick example:
# Averaging
>>> a = np.array([1, 2, 3, 4, 5, 6])
>>> b = np.array([6, 5, 4, 3, 2, 1])
>>> (a + b) / 2
array([3, 3, 3, 3, 3, 3])
And now let's take the "lighter" values for each position:
>>> np.max([a, b], axis=0)
array([6, 5, 4, 4, 5, 6])
This second method should work for you. Just "stack" the images and ask Numpy to return a new frame with the maximum values of each one. In an ideal world your background would be exactly the same and then np.max
would return different values only in the pixels where you've registered stars, giving you the trails.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.