Class: Pano::ImageFileSet
- Inherits:
-
Object
- Object
- Pano::ImageFileSet
- Defined in:
- lib/pano/image_file_set.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Instance Method Summary collapse
- #enfuse(dir, name, files = []) ⇒ Object
-
#initialize(dir_path) ⇒ ImageFileSet
constructor
A new instance of ImageFileSet.
- #spit_and_copy_files ⇒ Object
- #split_images ⇒ Object
Constructor Details
#initialize(dir_path) ⇒ ImageFileSet
Returns a new instance of ImageFileSet.
7 8 9 10 11 12 |
# File 'lib/pano/image_file_set.rb', line 7 def initialize dir_path @base_path = dir_path paths = Dir[File.join(@base_path,"*.JPG")] @files = paths.map {|path| ImageFile.new path } @files.sort_by &:created_at end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
5 6 7 |
# File 'lib/pano/image_file_set.rb', line 5 def base_path @base_path end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
5 6 7 |
# File 'lib/pano/image_file_set.rb', line 5 def files @files end |
Instance Method Details
#enfuse(dir, name, files = []) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/pano/image_file_set.rb', line 82 def enfuse dir, name, files = [] return if files.blank? FileUtils.mkpath dir contrast_weight = 0.6 entropy_weight = 0.4 exposure_weight = 0.5 saturation_weight = 0.2 target = File.join(dir, name + ".tif") input = files.map {|file| file.jpg_path }.join(" ") = "--contrast-weight=#{contrast_weight} --entropy-weight=#{entropy_weight} --exposure-weight=#{exposure_weight} --saturation-weight=#{saturation_weight} --compression=LZW" system "enfuse #{} -o #{target} #{input}" target end |
#spit_and_copy_files ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/pano/image_file_set.rb', line 47 def spit_and_copy_files puts "analysing files..." panos, misc = split_images panos.each_with_index do |pano, index| pano_dir = File.join(@base_path, "pano.#{index}") puts "coping to #{pano_dir}" pano.each do |file| file.copy_to pano_dir end i = 0 pano.each_slice(3) do |files| i+=1 fused = enfuse(File.join(pano_dir, "fused"), "%02d" % i, files) if (1..6).include? i system "convert #{fused} #{TOOL_ROOT}/lib/mask.png \ +matte -compose CopyOpacity -composite \ #{fused}" elsif i >= pano.length system "convert #{fused} #{TOOL_ROOT}/lib/mask_last.png \ +matte -compose CopyOpacity -composite \ #{fused}" end system "mogrift -rotate -90 #{fused}" system "exiftool -overwrite_original -TagsFromFile #{files.first.jpg_path} #{fused}" end end misc_dir = File.join(@base_path, "misc") puts "coping to #{misc_dir}" misc.each do |file| file.copy_to misc_dir end end |
#split_images ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pano/image_file_set.rb', line 14 def split_images pano = [] panos = [] misc = [] i = 0 while i < @files.length file = @files[i] if file.for_pano? if pano.length < 13 * 3 pano << file else last = pano.last if (file.created_at - last.created_at) > 1.5.minutes panos << pano pano = [] end pano << file end else if pano.present? panos << pano pano = [] end misc << file end i+=1 end if pano.present? panos << pano end [panos, misc] end |