class Mork::NPatch
@private NPatch
handles low-level computations on pixels by leveraging NArray
Public Class Methods
new(source, width, height)
click to toggle source
NPatch.new
(source, width, height) constructs an NPatch
object from the `source` linear array of bytes, to be reshaped as a `width` by `height` matrix
# File lib/mork/npatch.rb, line 10 def initialize(source, width, height) @patch = NArray.float(width, height) @patch[true] = source end
Public Instance Methods
average(coord)
click to toggle source
# File lib/mork/npatch.rb, line 15 def average(coord) @patch[coord.x_rng, coord.y_rng].mean end
centroid()
click to toggle source
# File lib/mork/npatch.rb, line 23 def centroid xp = @patch.sum(1).to_a yp = @patch.sum(0).to_a return xp.find_index(xp.min), yp.find_index(yp.min), @patch.stddev end
stddev(coord)
click to toggle source
# File lib/mork/npatch.rb, line 19 def stddev(coord) @patch[coord.x_rng, coord.y_rng].stddev end