-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
hello deluan,
first thank you for this very useful library.
i rewrote the numerator() function. usually one would send a pull request, but i know norhing about git (mercurial user).
so i just paste my version here:
func numerator(img *imageBinaryChannel, template *imageBinaryChannel, offsetX int, offsetY int) float64 {
imgArray := img.zeroMeanImage
templateArray := template.zeroMeanImage
iidx := offsetY*img.width + offsetX
idelta := img.width - template.width
tidx := 0
var sum float64 = 0
for y := 0; y < template.height; y++ {
for x := 0; x < template.width; x++ {
sum += imgArray[iidx] * templateArray[tidx]
iidx++
tidx++
}
iidx += idelta
}
return sum
}
two big changes:
1st: i pulled constanst computations out of the loop, as they don't change.
2nd:i swapped the loop order - y outer loop, x inner loop.
this way the loop is a lot more cache friendly
the new code is not only faster but a lot simpler and easier to understand.
on my machine i got a speed improvement of 20%. hope you find this useful!
regards,
dederon
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels