Sha256: 6048271087648a220d9613a65c850e0680ad6d23bbf09d1fb0483f08275a98f6
Contents?: true
Size: 1.49 KB
Versions: 3
Compression:
Stored size: 1.49 KB
Contents
require 'narray' module Mork # @private # NPatch handles low-level computations on pixels by leveraging NArray class NPatch # 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 def initialize(source, width, height) @patch = NArray.float(width, height) @patch[true] = source end def average(coord) @patch[coord.x_rng, coord.y_rng].mean end def stddev(coord) @patch[coord.x_rng, coord.y_rng].stddev end 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 end end # def dark_centroid(c = nil) # p = crop c # sufficient_contrast?(p) or return # xp = p.sum(1).to_a # yp = p.sum(0).to_a # # find the intensity trough # ctr_x = xp.find_index(xp.min) # ctr_y = yp.find_index(yp.min) # # puts "Centroid: #{ctr_x}, #{ctr_y} - MinX #{xp.min/xp.length}, MaxX #{xp.max/xp.length}, MinY #{yp.min/yp.length}, MaxY #{yp.max/yp.length}" # return ctr_x, ctr_y # end # def crop(c) # raise "crop HELL" if c.nil? # p = NArray.float c.w, c.h # p[true,true] = @patch[c.x_rng, c.y_rng] # p # end # def sufficient_contrast?(p) # # puts "Contrast: #{p.stddev}" # # tested with the few examples: spec/samples/rm0x.jpeg # p.stddev > 20 # end # def length # # is this only going to be used for testing purposes? # @patch.length # end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mork-0.11.2 | lib/mork/npatch.rb |
mork-0.11.1 | lib/mork/npatch.rb |
mork-0.10.0 | lib/mork/npatch.rb |