Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixes issue 1

Dark frames now averaged and then differenced from each light frame

Need to supply width and height removed.  Now calculated based on the 1st image we load.

New function to check if a file is an image as it's a common task.
  • Loading branch information...
commit fc62eb51885df81549130a5f81de5d3bd9f3f082 1 parent 576ff53
chris@cpearson.me.uk authored
Showing with 97 additions and 39 deletions.
  1. +13 −0 README.txt
  2. +84 −39 startrail.py
View
13 README.txt
@@ -0,0 +1,13 @@
+1.2
+===============
+Removed need to specify width and height, now worked out using the 1st frame.
+Corrected handling of dark frames. Dark frames are 1st averaged into a single dark image this is then differenced from each light frame prior to layering via lighten.
+
+1.1
+===============
+Removed need to specify the file extension of the frames
+General tidy up of code
+
+1.0
+===============
+Initial Release
View
123 startrail.py
@@ -3,7 +3,7 @@
#
# Gimp Startrail Compositor
# http://code.google.com/p/gimp-startrail-compositor/
-# Version : 1.1
+# Version : 1.2
#
# Christopher Pearson
# www.cpearson.me.uk
@@ -29,38 +29,81 @@
gettext.install( "gimp20-template" , locale_directory, unicode=True )
allowedTypes = ["jpg","jpeg","tiff","tif","bmp","png"]
+LIGHTEN = 10
+DIFFERENCE = 6
-def createStarterImage(width, height):
- # Create a new image to work in.
- image = gimp.Image(width, height, RGB)
-
- # Create a new layer to form our background
- bg = gimp.Layer(image, "", width, height, RGB_IMAGE, 100, NORMAL_MODE)
- image.add_layer(bg, 0)
- # Save off the old BG colour as they may want to keep it.
- old_background = gimp.get_background()
+def fileIsImage(fileName):
+ isImage = 0
+ ext = os.path.splitext(fileName)[1] # get the extension
+ ext = ext.replace(".", "") # rip off the . from the extension
+ if ext.lower() in allowedTypes: # is this an image?
+ isImage = 1
+ return(isImage)
+
+def processDarkFrame(fileName, image, layerCount):
+ darkFrame = pdb.gimp_file_load(fileName,"")
+
+ # have we got a base image to work with?
+ if image == None:
+ # create a base image based on the dark frame
+ image = pdb.gimp_image_new(darkFrame.active_layer.width, darkFrame.active_layer.height, 0)
+
+ # get the main layer of the new frame
+ darkLayer = pdb.gimp_layer_new_from_drawable(darkFrame.active_layer, image)
+ # set the opacity to half that of the one before so we get an average
+ darkLayer.opacity = 100.0 / layerCount
+ # add the new layer and flatten down to keep memory useage down.
+ image.add_layer(darkLayer,0)
+ image.flatten()
+ # Get rid of the image we loaded up.
+ gimp.delete(darkFrame)
+ return(image)
- # Fill the new layer with black so the lighten process works.
- gimp.set_background(0, 0, 0)
- bg.fill(BACKGROUND_FILL)
+def createDarkImage(darkFrames):
+ darkImage = None
+ layerCount = 1
+
+ for fileName in os.listdir(darkFrames):
+ fileName = os.path.join(darkFrames, fileName)
+ if fileIsImage(fileName):
+ darkImage = processDarkFrame(fileName, darkImage, layerCount)
+ layerCount += 1
+
+ return darkImage
- # put the old background back.
- gimp.set_background(old_background)
+def processLightFrame(fileName, image, darkImage):
+ # load up the light frame into an image
+ lightFrame = pdb.gimp_file_load(fileName,"")
+
+ # have we got a base image to work with?
+ if image == None:
+ # create a base image based on the light frame
+ image = pdb.gimp_image_new(lightFrame.active_layer.width, lightFrame.active_layer.height, 0)
- # We're done messing with the background so flatten down.
+ # did we make a dark frame?
+ if darkImage != None:
+ # As we have a dark image we need to difference it against the light frame.
+ # create a new layer from the dark image
+ darkLayer = pdb.gimp_layer_new_from_drawable(darkImage.active_layer, lightFrame)
+ # set the layer to difference
+ darkLayer.mode = DIFFERENCE
+ # add the layer to the lightFrame
+ lightFrame.add_layer(darkLayer, 0)
+ # flatten
+ lightFrame.flatten()
+
+ # Set the light frame to lighten
+ lightLayer = pdb.gimp_layer_new_from_drawable (lightFrame.active_layer, image)
+ lightLayer.mode = LIGHTEN
+ # add this as new layer
+ image.add_layer(lightLayer,0)
image.flatten()
- return (image)
-def processImage(fileName, image, layerMode):
- ext = os.path.splitext(fileName)[1] # get the extension
- ext = ext.replace(".", "") # rip off the . from the extension
- if ext.lower() in allowedTypes: # is this an image?
- newLayer = pdb.gimp_file_load_layer(image, fileName)
- newLayer.mode = layerMode
- image.add_layer(newLayer,0)
- image.flatten()
+ # clean up our temp bits.
+ gimp.delete(lightFrame)
+ return(image)
-def startrail(width, height, frames, dark_frames):
+def startrail(frames, darkFrames):
#Do some santity checking before we start
if len(frames) == 0:
pdb.gimp_message("No light frame path provided.")
@@ -70,19 +113,23 @@ def startrail(width, height, frames, dark_frames):
pdb.gimp_message("Light frame path doesn't exist.")
return
- # Create a new image to work in.
- image = createStarterImage(width, height)
-
+ # create our dark frame averaged from all of them
+ darkImage = createDarkImage(darkFrames)
+
+ # Define an image to work in.
+ # This will be created from the first light frame we process
+ image = None
for fileName in os.listdir(frames):
- processImage(os.path.join(frames, fileName), image, 10) # Lighten mode.
+ fileName = os.path.join(frames, fileName)
+ if fileIsImage(fileName):
+ image = processLightFrame(fileName, image, darkImage)
- # If there is a specified path and that path exists then process the dark frames.
- if os.path.exists(dark_frames):
- for fileName in os.listdir(dark_frames):
- processImage(os.path.join(dark_frames, fileName), image, 6) # Difference mode.
-
- # show the new image
- gimp.Display(image)
+ # show the new image if we managed to make one.
+ if image == None:
+ pdb.gimp_message("No images found to stack")
+ else:
+ gimp.Display(image)
+ gimp.delete(darkImage) # we don't need this any more so get rid of it so not to leak.
register(
"startrail",
@@ -94,8 +141,6 @@ def startrail(width, height, frames, dark_frames):
_("Startrail"),
"",
[
- (PF_INT, "width", "Width",3008),
- (PF_INT, "height", "Height",2000),
(PF_DIRNAME, "frames","Light Frames",""),
(PF_DIRNAME, "dark_frames","Dark Frames","")
],
Please sign in to comment.
Something went wrong with that request. Please try again.