Last active
December 3, 2016 20:00
-
-
Save farrajota/ab55610652f008ba8719a5e1c5960df4 to your computer and use it in GitHub Desktop.
Sub-pixel precision using 1D parabola fitting
This file contains 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
-- Use three (consecutive) points to fit a 1D parabola | |
-- and return its maximum value. To achieve sub-pixel | |
-- precision for a 2D maxima (x,y), just fit the parabola over the | |
-- x and y coordinates separately with two neighboring points. | |
local function fitParabola(x1,x2,x3,y1,y2,y3) | |
local x1_sqr = x1*x1 | |
local x2_sqr = x2*x2 | |
local x3_sqr = x3*x3 | |
local div = (x1_sqr-x1*(x2+x3)+x2*x3)*(x2-x3) | |
local a = (x1*(y2-y3)-x2*(y1-y3)+x3*(y1-y2))/div | |
local b = (x1_sqr*(y2-y3)-x2_sqr*(y1-y3)+x3_sqr*(y1-y2))/div | |
return b/(2*a) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment