General two-dimensional least-squares image subtraction