Skip to content

Instantly share code, notes, and snippets.

@Neurogami
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Neurogami/025015ac17707a8abbef to your computer and use it in GitHub Desktop.
Save Neurogami/025015ac17707a8abbef to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Assumes you have ImageMagick installed
class MakeAverages
def initialize base_name, ext, grouping, prefix = 'avg_'
@base_name = base_name
@ext = ext
@grouping = grouping.to_i
@prefix = prefix
end
def run
images = Dir.glob("#{@base_name}*.#{@ext}").sort
if images.size == 0
raise "Faled to find any images matching '#{@base_name}*.#{@ext}'"
end
images.each_with_index do |img, idx|
set = images[idx...(idx+@grouping)]
if set.size < @grouping
warn 'Out of images!'
return
end
new_file = "#{@prefix}#{@base_name}.#{idx.to_s.rjust 4, '0'}.#{@ext}"
cmd = "convert #{set.join ' '} -evaluate-sequence mean #{new_file}"
puts cmd
warn `#{cmd}`
end
end
end
if __FILE__ == $0
if ARGV.size < 3
puts "usage: #{__FILE__} base_name, file_extension, grouping_number"
exit
end
ai = MakeAverages.new *ARGV
ai.run
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment