Class: Treyja::Command::Image
- Inherits:
-
Object
- Object
- Treyja::Command::Image
- Defined in:
- lib/treyja/command/image.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#output_dir ⇒ Object
readonly
Returns the value of attribute output_dir.
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
Instance Method Summary collapse
- #chunk(type, data) ⇒ Object
-
#initialize(reader, output_dir, options = {}) ⇒ Image
constructor
A new instance of Image.
- #run ⇒ Object
Constructor Details
#initialize(reader, output_dir, options = {}) ⇒ Image
Returns a new instance of Image.
8 9 10 11 12 |
# File 'lib/treyja/command/image.rb', line 8 def initialize reader, output_dir, = {} @reader = reader @output_dir = output_dir @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/treyja/command/image.rb', line 6 def @options end |
#output_dir ⇒ Object (readonly)
Returns the value of attribute output_dir.
6 7 8 |
# File 'lib/treyja/command/image.rb', line 6 def output_dir @output_dir end |
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
6 7 8 |
# File 'lib/treyja/command/image.rb', line 6 def reader @reader end |
Instance Method Details
#chunk(type, data) ⇒ Object
89 90 91 |
# File 'lib/treyja/command/image.rb', line 89 def chunk(type, data) [data.bytesize, type, data, Zlib.crc32(type + data)].pack("NA4A*N") end |
#run ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/treyja/command/image.rb', line 14 def run FileUtils.mkdir_p output_dir reader.each_with_index do |tensors, i| tensors.tensors.each_with_index do |tensor, j| n = tensor.dims.drop(3).inject(1, :*) # Drop width, height and channel and fold the rest n.times.each do |k| postfix = ([i, j] + (n > 1 ? [k] : [])).map(&:to_s).join('-') dst = File.join(output_dir, "image-#{postfix}.png") write_image tensor, k, dst end end end reader.each do |ts| p ts STDOUT.flush end end |