The min/max approach to calculating offsets often does not work well, and the offsets are only part of the total correction, which includes correcting for differences in X and Y scale factors, plus "soft iron" environmental distortions.
See code in reply #2.