Class: NeuralNetworkRb::MNISTImage
- Inherits:
-
Object
- Object
- NeuralNetworkRb::MNISTImage
- Defined in:
- lib/neural_network_rb/mnist_image.rb
Instance Method Summary collapse
-
#initialize(pixels) ⇒ MNISTImage
constructor
A new instance of MNISTImage.
- #save_to_file(file_path) ⇒ Object
Constructor Details
#initialize(pixels) ⇒ MNISTImage
Returns a new instance of MNISTImage.
5 6 7 |
# File 'lib/neural_network_rb/mnist_image.rb', line 5 def initialize(pixels) @pixels = pixels end |
Instance Method Details
#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 |