Class: Rbmnist::ImageWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/rbmnist/image_wrapper.rb

Constant Summary collapse

WIDTH =
28
HEIGHT =
28

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ImageWrapper

Returns a new instance of ImageWrapper.



8
9
10
# File 'lib/rbmnist/image_wrapper.rb', line 8

def initialize(data)
    @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/rbmnist/image_wrapper.rb', line 6

def data
  @data
end

Instance Method Details

#[](arg) ⇒ Object



20
21
22
# File 'lib/rbmnist/image_wrapper.rb', line 20

def [](arg)
    @data[arg]
end

#[]=(val, newval) ⇒ Object



24
25
26
# File 'lib/rbmnist/image_wrapper.rb', line 24

def []=(val, newval)
    @data[val] = newval
end

#each(&block) ⇒ Object



28
29
30
# File 'lib/rbmnist/image_wrapper.rb', line 28

def each(&block)
    @data.each(&block)
end

#map(&block) ⇒ Object



32
33
34
# File 'lib/rbmnist/image_wrapper.rb', line 32

def map(&block)
    @data.map(&block)
end

#pixelsObject



12
13
14
# File 'lib/rbmnist/image_wrapper.rb', line 12

def pixels
    @data
end

#to_aObject



16
17
18
# File 'lib/rbmnist/image_wrapper.rb', line 16

def to_a
    return data
end

#to_a_2dObject



36
37
38
39
40
41
42
# File 'lib/rbmnist/image_wrapper.rb', line 36

def to_a_2d
    Array.new(HEIGHT) do |row|
        rowstart = row * WIDTH
        rowend = rowstart + WIDTH
        @data[rowstart...rowend]
    end
end

#to_pngObject



44
45
46
# File 'lib/rbmnist/image_wrapper.rb', line 44

def to_png
    Rbimg::PNG.new(pixels: @data, type: :greyscale, width: WIDTH, height: HEIGHT)
end