1. A computer-implemented method for gain calibration comprising: sorting calibration data for each pixel location from offset-corrected X-ray image data into a sequence; removing part of the calibration data on one end or both ends of the sequence for each pixel location; averaging the calibration data remaining within each respective sequence to obtain an average pixel value for each pixel location; and generating a gain map based on the average pixel value for each pixel location.