Class: Hornetseye::MultiArray
- Extended by:
- MultiArrayConstructor
- Defined in:
- docs/multiarray/lib/multiarray/multiarray.rb,
docs/hornetseye-openexr/lib/hornetseye-openexr/multiarray.rb,
docs/hornetseye-rmagick/lib/hornetseye-rmagick/multiarray.rb
Overview
This class provides methods for initialising multi-dimensional arrays
Class Method Summary collapse
-
.[](*args) ⇒ Node
Convert Ruby array to uniform multi-dimensional array.
-
.import(typecode, data, *shape) ⇒ Node
Import array from string.
-
.laplacian_of_gaussian(sigma = 1.4, size = 9) ⇒ Object
Compute Laplacian of Gaussian filter.
- .load_dfloat(file) ⇒ Object
- .load_dfloatrgb(file) ⇒ Object
- .load_magick(file) ⇒ Object
- .load_openexr(file) ⇒ Object
- .load_sfloat(file) ⇒ Object
- .load_sfloatrgb(file) ⇒ Object
- .load_ubyte(file) ⇒ Object
- .load_ubytergb(file) ⇒ Object
- .load_uint(file) ⇒ Object
- .load_uintrgb(file) ⇒ Object
- .load_usint(file) ⇒ Object
- .load_usintrgb(file) ⇒ Object
- .new(typecode, *shape) ⇒ Object
Instance Method Summary collapse
Class Method Details
.[](*args) ⇒ Node
Convert Ruby array to uniform multi-dimensional array
Type matching is used to find a common element type. Furthermore the required shape of the array is determined. Finally the elements are coopied to the resulting array.
58 59 60 61 |
# File 'docs/multiarray/lib/multiarray/multiarray.rb', line 58 def []( *args ) target = Node.fit args target[ *args ] end |
.import(typecode, data, *shape) ⇒ Node
Import array from string
Create an array from raw data provided as a string.
38 39 40 41 42 43 44 45 46 47 |
# File 'docs/multiarray/lib/multiarray/multiarray.rb', line 38 def import( typecode, data, *shape ) t = Hornetseye::MultiArray typecode, shape.size if data.is_a? Malloc memory = data else memory = Malloc.new t.storage_size(*shape) memory.write data end t.new *(shape + [:memory => memory]) end |
.laplacian_of_gaussian(sigma = 1.4, size = 9) ⇒ Object
Compute Laplacian of Gaussian filter
@return The filter.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'docs/multiarray/lib/multiarray/multiarray.rb', line 69 def laplacian_of_gaussian( sigma = 1.4, size = 9 ) def erf( x, sigma ) 0.5 * Math.erf( x / ( Math.sqrt( 2.0 ) * sigma.abs ) ) end def gauss_gradient( x, sigma ) -x / ( Math.sqrt( 2.0 * Math::PI * sigma.abs**5 ) ) * Math.exp( -x**2 / ( 2.0 * sigma**2 ) ) end retval = new DFLOAT, size, size sum = 0 for y in 0 .. size - 1 y0 = y - 0.5 * size y1 = y0 + 1 y_grad_diff = gauss_gradient( y1, sigma ) - gauss_gradient( y0, sigma ) y_erf_diff = erf( y1, sigma ) - erf( y0, sigma ) for x in 0..size-1 x0 = x - 0.5 * size x1 = x0 + 1 x_grad_diff = gauss_gradient( x1, sigma ) - gauss_gradient( x0, sigma ) x_erf_diff = erf( x1, sigma ) - erf( x0, sigma ) retval[ y, x ] = y_grad_diff * x_erf_diff + y_erf_diff * x_grad_diff end end retval end |
.load_dfloat(file) ⇒ Object
30 31 32 |
# File 'docs/hornetseye-openexr/lib/hornetseye-openexr/multiarray.rb', line 30 def load_dfloat( file ) OpenEXRInput.new( file ).read.to_type DFLOAT end |
.load_dfloatrgb(file) ⇒ Object
38 39 40 |
# File 'docs/hornetseye-openexr/lib/hornetseye-openexr/multiarray.rb', line 38 def load_dfloatrgb( file ) OpenEXRInput.new( file ).read.to_type DFLOATRGB end |
.load_magick(file) ⇒ Object
22 23 24 |
# File 'docs/hornetseye-rmagick/lib/hornetseye-rmagick/multiarray.rb', line 22 def load_magick( file ) Magick::Image.read( file ).first.to_multiarray end |
.load_openexr(file) ⇒ Object
22 23 24 |
# File 'docs/hornetseye-openexr/lib/hornetseye-openexr/multiarray.rb', line 22 def load_openexr( file ) OpenEXRInput.new( file ).read end |
.load_sfloat(file) ⇒ Object
26 27 28 |
# File 'docs/hornetseye-openexr/lib/hornetseye-openexr/multiarray.rb', line 26 def load_sfloat( file ) OpenEXRInput.new( file ).read.to_type SFLOAT end |
.load_sfloatrgb(file) ⇒ Object
34 35 36 |
# File 'docs/hornetseye-openexr/lib/hornetseye-openexr/multiarray.rb', line 34 def load_sfloatrgb( file ) OpenEXRInput.new( file ).read.to_type SFLOATRGB end |
.load_ubyte(file) ⇒ Object
26 27 28 |
# File 'docs/hornetseye-rmagick/lib/hornetseye-rmagick/multiarray.rb', line 26 def load_ubyte( file ) Magick::Image.read( file ).first.to_type UBYTE end |
.load_ubytergb(file) ⇒ Object
38 39 40 |
# File 'docs/hornetseye-rmagick/lib/hornetseye-rmagick/multiarray.rb', line 38 def load_ubytergb( file ) Magick::Image.read( file ).first.to_type UBYTERGB end |
.load_uint(file) ⇒ Object
34 35 36 |
# File 'docs/hornetseye-rmagick/lib/hornetseye-rmagick/multiarray.rb', line 34 def load_uint( file ) Magick::Image.read( file ).first.to_type UINT end |
.load_uintrgb(file) ⇒ Object
46 47 48 |
# File 'docs/hornetseye-rmagick/lib/hornetseye-rmagick/multiarray.rb', line 46 def load_uintrgb( file ) Magick::Image.read( file ).first.to_type UINTRGB end |
.load_usint(file) ⇒ Object
30 31 32 |
# File 'docs/hornetseye-rmagick/lib/hornetseye-rmagick/multiarray.rb', line 30 def load_usint( file ) Magick::Image.read( file ).first.to_type USINT end |
.load_usintrgb(file) ⇒ Object
42 43 44 |
# File 'docs/hornetseye-rmagick/lib/hornetseye-rmagick/multiarray.rb', line 42 def load_usintrgb( file ) Magick::Image.read( file ).first.to_type USINTRGB end |
.new(typecode, *shape) ⇒ Object
25 26 27 |
# File 'docs/multiarray/lib/multiarray/multiarray.rb', line 25 def new(typecode, *shape) Hornetseye::MultiArray(typecode, shape.size).new *shape end |