Class: Magick::Image

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

Instance Method Summary collapse

Instance Method Details

#to_arrayObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/disp3D_ext.rb', line 19

def to_array
  return nil if(self.nil?)
  channel_size = 3
  data_ary = Array.new(self.columns * self.rows * channel_size)
  max_color_intensity =  Magick::QuantumRange.to_f
  idx = -1
  self.each_pixel do | pixel, c, r |
    data_ary[idx+=1] = pixel.red / max_color_intensity
    data_ary[idx+=1] = pixel.green / max_color_intensity
    data_ary[idx+=1] = pixel.blue / max_color_intensity
  end
  return data_ary
end