Images captured with a typical endoscope show spatial distortion, which necessitates distortion correction for subsequent analysis. Here, a new methodology based on least squares estimation is proposed to correct the nonlinear distortion in the endoscopic images. A mathematical model based on polynomial mapping is used to map the images from distorted image space onto the corrected image space. The model parameters include the polynomial coefficients, distortion center, and corrected center. The proposed method utilizes a line search approach of global convergence for the iterative procedure to obtain the optimum expansion coefficients. A new technique to find the distortion center of the image based on curvature criterion is presented. A dual-step approach comprising token matching and integrated neighborhood search is also proposed for accurate extraction of the centers of the dots contained in a rectangular grid, used for the model parameter estimation. The model parameters were verified with different grid patterns. The distortion correction model is applied to several gastrointestinal images and the results are presented. The proposed technique provides high-speed response and forms a key step toward online camera calibration, which is required for accurate quantitative analysis of the images.