Sunday, September 30, 2012

Image Stacking: Using Filters

Now that we have played with the most basic image stacking, we can start to think of interesting ways to accentuate certain aspects of an image. For example, if we want to capture stars we want to preserve the brightness of the star. If we simply perform the previous averaging,  one bright pixel averaged with 100 other dark pixels will result in a dark pixel. PIL happens to have an interesting function that will compare to images and return a new image with the brightest pixels from both input images:

from PIL import ImageChops
resultIm = ImageChops.lighter(im1,im2)

If we use this on a series of images, comparing the next image to the result image, we essentially create an image of the brightest pixels from the image series. This can be accomplished in python by using code along these lines:

from PIL import Image, ImageChops
import glob

imgList = glob.glob('./*.jpg')

resultIm = Image.open(imgList[0])
for i in range(1,len(imgList)):
    tempIm = Image.open(imgList[i])
    resultIm = ImageChops.lighter(resultIm, tempIm)

resultIm.show()

Using an image series (ISS030-E-271717-ISS030-E-271798) from  over here and the above code generates this image:

Images courtesy of the Image Science & Analysis Laboratory, NASA Johnson Space Center

No comments:

Post a Comment