Gradient-based subpixel registration algorithm