By using the complex representation of quaternion matrices, and the Moore–Penrose generalized inverse, we derive the expressions of the least squares solution with the least norm, the least squares pure imaginary solution with the least norm, and the least squares real solution with the least norm for the quaternion matrix equation AX=B, respectively. Finally, we discuss their applications in color image restoration.