Sha256: 9ef9dd0641885464ae41545131a4888b1206ea994d9bd1793d01b12cfc9cdb93
Contents?: true
Size: 1.03 KB
Versions: 7
Compression:
Stored size: 1.03 KB
Contents
require 'narray' module Mork # Handles low-level computations on a Mimage # Typically used on smaller patches class NPatch def initialize(mim) @mim = mim @width = mim.width @height = mim.height end def average narr.mean end def dark_centroid sufficient_contrast? or return xp = patch.sum(1).to_a yp = patch.sum(0).to_a # find the intensity trough ctr_x = xp.find_index(xp.min) ctr_y = yp.find_index(yp.min) # return :edgy if edgy?(ctr_x, ctr_y) return ctr_x, ctr_y end private def patch @the_npatch ||= blurry_narr.reshape!(@width, @height) end def narr NArray[@mim.pixels] end def blurry_narr @blurry_narr ||= NArray[@mim.blur!(10,5).pixels] end def sufficient_contrast? # just a wild guess for now blurry_narr.stddev > 5000 end def edgy?(x, y) tol = 5 (x < tol) or (y < tol) or (y > @height - tol) or (x > @width - tol) end end end
Version data entries
7 entries across 7 versions & 1 rubygems