Last active
August 29, 2015 14:01
-
-
Save Neurogami/025015ac17707a8abbef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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