Compared to the dual-energy scintillator detectors widely used today, energy-resolved photon-counting x-ray detectors show the potential to improve material identification in various radiography and tomography applications used for industrial and security purposes. However, detector effects, such as charge sharing and photon pileup, distort the measured spectra in pixelated, photon-counting detectors operating under high flux. These effects result in a significant performance degradation of the detectors when used for material identification where accurate spectral measurements are required. We have developed a semianalytical, postdata acquisition, computational algorithm that corrects the measured attenuation curve for severe spectral distortions caused by the detector. The calibration of the algorithm is based on simple attenuation measurements of commercially available materials using standard laboratory sources, enabling the algorithm to be used in any x-ray setup. The algorithm is developed for correcting spectral data acquired with the MultiX ME100 CdTe x-ray detector but could be adapted with small adjustments to other photon-counting, energy-resolved detectors with CdTe sensors. The validation of the algorithm has been done using experimental data acquired with both a standard laboratory source and synchrotron radiation. The experiments show that the algorithm is fast, reliable at x-ray flux up to 5 Mph / s / mm2 and greatly improves the accuracy of the measured spectrally resolved linear attenuation, making the algorithm useful for both security and industrial applications where photon-counting detectors are used.