Pattern noise and nonlinearity are common problems in many image sensors that limit their performance. We present an algorithm based on neural network to correct pattern noise and nonlinearity of the image sensor when the gray value approaches the saturation point to improve the linear range and image contrast of image sensors. The photon transfer curve (PTC) of each pixel is evaluated through a photographic test with an image sensor at different exposures. Assuming that the PTC of the ideal image sensor is a proportional function, the nonlinear region of the PTC of each pixel is corrected to the targeted curve using a neural network. The experimental results show that the image contrast and dynamic range of the corrected image can be significantly improved while the pattern noise of the corrected image is also effectively removed. In addition, the algorithm corrects the damaged pixels of the image sensor.