Abstract In conventional X-ray imaging of a composed object only the cumulative attenuation is accessible, but the contribution of different materials can not be resolved. We consider the object consisting of known basis materials. Our method of material reconstruction provides the areal densities of these basis materials in each pixel of the image. This method uses the different energy dependences of X-ray attenuation of the basis materials to distinguish between them. It obviously requires a spectroscopic detector. Pixelated hybrid semiconductor X-ray detectors such as the Medipix2 suffer from charge sharing between pixels. This leads to a deteriorated energy response of the detector. To overcome this problem, we present two different methods to reconstruct incident X-ray spectra from threshold scans in each pixel. Both methods, namely spectrum stripping and a linear least squares fit, employ MC-simulated energy response functions to monoenergetic irradiation. Both methods work very well. The reconstructed incident spectra allow the application of material reconstruction with Medipix2. We present the material resolved images of a phantom containing aluminum, acrylic glass (PMMA) and iodine. This method allows new applications in non-destructive testing and medical imaging. This work was carried out within the Medipix-collaboration.