Method: NeuralNetworkRb::MNISTImage#save_to_file

Defined in:
lib/neural_network_rb/mnist_image.rb

#save_to_file(file_path) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/neural_network_rb/mnist_image.rb', line 9

def save_to_file(file_path)
  size = Math.sqrt(@pixels.length).to_i
  square = ChunkyPNG::Canvas.new(size, size, ChunkyPNG::Color::TRANSPARENT)
  size.times do |i| 
    size.times do |j|
      square[j, i] = @pixels[i*size + j]
    end
  end
  square.to_image.save(file_path)
end