mnist-ready 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/draw_image.rb +41 -0
- data/lib/mnist_digit.rb +6 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e7b27f81d9d8aa860901b53d849477e1c204fe97f9ee18811caba4fa3b1bf02
|
4
|
+
data.tar.gz: 7de49c1978d0457021e28be6f4906685af00ca18bd90cdc5c37d637d32f61445
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84a37ee74b5d893fd3e0f4fce0eb1e90deb7b925e4a6b89094aa3ea9f1ba1f0610f9139ef7d57e7cf5be62e40a5a054164751443d3476db27d81cfb0bf00b108
|
7
|
+
data.tar.gz: 2c7882315bff945712be2c85c3a820fe11fdfaad47c132c8c2a130a350031bab6a05e6d99410cec36b5f71ce20fb43303b2a83d9efd8f4a3cf0eff30ef6935bf
|
data/lib/draw_image.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rmagick'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
class DrawImage
|
5
|
+
|
6
|
+
def self.draw(pixel_array, white_background = false)
|
7
|
+
|
8
|
+
# Create a new 28x28 image
|
9
|
+
image = Magick::Image.new(28, 28)
|
10
|
+
|
11
|
+
# Set each pixel in the image
|
12
|
+
28.times do |y|
|
13
|
+
28.times do |x|
|
14
|
+
pixel_value = pixel_array[y * 28 + x]
|
15
|
+
pixel_value = 255 - pixel_value if white_background
|
16
|
+
color = Magick::Pixel.new(pixel_value * 257, pixel_value * 257, pixel_value * 257)
|
17
|
+
image.pixel_color(x, y, color)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Scale up the image to make it more visible
|
22
|
+
image = image.scale(10)
|
23
|
+
|
24
|
+
# Set the format to PNG
|
25
|
+
image.format = 'PNG'
|
26
|
+
|
27
|
+
# Convert the image to a blob
|
28
|
+
blob = image.to_blob
|
29
|
+
|
30
|
+
# Encode the blob as base64
|
31
|
+
encoded_image = Base64.strict_encode64(blob)
|
32
|
+
|
33
|
+
# Display the image inline using iTerm2's imgcat escape sequence
|
34
|
+
puts "\033]1337;File=inline=1;size=#{blob.size}:#{encoded_image}\007"
|
35
|
+
|
36
|
+
# Force a newline after the image
|
37
|
+
puts "\n"
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/lib/mnist_digit.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mnist-ready
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergio Oliveira Jr
|
@@ -9,7 +9,21 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2024-09-19 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rmagick
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6.0'
|
13
27
|
description:
|
14
28
|
email: sergio.oliveira.jr@gmail.com
|
15
29
|
executables: []
|
@@ -20,6 +34,7 @@ files:
|
|
20
34
|
- data/mnist_train1.csv
|
21
35
|
- data/mnist_train2.csv
|
22
36
|
- data/mnist_train3.csv
|
37
|
+
- lib/draw_image.rb
|
23
38
|
- lib/mnist-ready.rb
|
24
39
|
- lib/mnist_dataset.rb
|
25
40
|
- lib/mnist_digit.rb
|