A system for performing ambient light image correction, the system comprising: a light source configured to provide pulsed illumination to a subject; an imaging unit configured to capture, while the subject is illuminated by the pulsed illumination from the light source, a plurality of images of the subject, wherein each of the plurality of images is captured at an exposure time shorter than the wave period of the pulsed illumination, wherein the pulse frequency of the illumination provided by the light source is not a multiple integral of the frame rate at which the plurality of images are captured by the imaging unit, and wherein a total time during which the plurality of images is captured is at least half of the wave period of the pulsed illumination; and a control unit configured to: obtain a predetermined number n of captured images, the candidate images, wherein the candidate images are n sequential captured images; generate, for each of every pixel location in the plurality of candidate images, a sorted list of pixels by sorting respective pixels each corresponding to the respective pixel location in the plurality of candidate images, wherein the sorting is based on the pixel value of the respective pixels; apply, for each of every pixel location in the plurality of candidate images, a set of weights to the respective sorted list of pixels, wherein the set of weights is associated with a least squares approximation of a probability density function of the pixel value over time; and generate an estimated ambient light corrected image based on the plurality of weighted and sorted lists of pixels by summing the plurality of weighted and sorted lists of pixels. a light source configured to provide pulsed illumination to a subject; an imaging unit configured to capture, while the subject is illuminated by the pulsed illumination from the light source, a plurality of images of the subject, wherein each of the plurality of images is captured at an exposure time shorter than the wave period of the pulsed illumination, wherein the pulse frequency of the illumination provided by the light source is not a multiple integral of the frame rate at which the plurality of images are captured by the imaging unit, and wherein a total time during which the plurality of images is captured is at least half of the wave period of the pulsed illumination; and a control unit configured to: obtain a predetermined number n of captured images, the candidate images, wherein the candidate images are n sequential captured images; generate, for each of every pixel location in the plurality of candidate images, a sorted list of pixels by sorting respective pixels each corresponding to the respective pixel location in the plurality of candidate images, wherein the sorting is based on the pixel value of the respective pixels; apply, for each of every pixel location in the plurality of candidate images, a set of weights to the respective sorted list of pixels, wherein the set of weights is associated with a least squares approximation of a probability density function of the pixel value over time; and generate an estimated ambient light corrected image based on the plurality of weighted and sorted lists of pixels by summing the plurality of weighted and sorted lists of pixels. obtain a predetermined number n of captured images, the candidate images, wherein the candidate images are n sequential captured images; generate, for each of every pixel location in the plurality of candidate images, a sorted list of pixels by sorting respective pixels each corresponding to the respective pixel location in the plurality of candidate images, wherein the sorting is based on the pixel value of the respective pixels; apply, for each of every pixel location in the plurality of candidate images, a set of weights to the respective sorted list of pixels, wherein the set of weights is associated with a least squares approximation of a probability density function of the pixel value over time; and generate an estimated ambient light corrected image based on the plurality of weighted and sorted lists of pixels by summing the plurality of weighted and sorted lists of pixels.