Created
March 22, 2010 16:15
-
-
Save rubyredrick/340227 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| require 'hornetseye' | |
| include Hornetseye | |
| class Sequence_ | |
| def avg | |
| sum / size | |
| end | |
| def sqr | |
| self * self | |
| end | |
| def corr( other ) | |
| ( rfft * other.rfft.conj ).irfft | |
| end | |
| def zcorr( other ) | |
| zother = MultiArray.dfloat( *shape ).fill! | |
| zother[ 0 ... other.shape[0], 0 ... other.shape[1] ] = other | |
| corr zother | |
| end | |
| def median( *shape ) | |
| filter = MultiArray.dfloat( *shape ).fill! 1 | |
| zcorr filter | |
| end | |
| def ncc( other, noise ) | |
| zcorr( other - other.avg ) / | |
| Math.sqrt( ( sqr.median( *other.shape ) - | |
| median( *other.shape ).sqr / other.size ) * | |
| ( other - other.avg ).sqr.sum + noise ) | |
| end | |
| end | |
| raise "Syntax: ./findnumbers.rb <input image> <number image>" if ARGV.size != 2 | |
| image = MultiArray.load_ubytergb(ARGV[0]) | |
| template = MultiArray.load_ubytergb(ARGV[1]) | |
| debugger | |
| ncc = image.to_dfloat.ncc(template.to_dfloat, 0.1) | |
| idx = MultiArray.int(*ncc.shape).indgen!.mask(ncc >= ncc.max)[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment