-This paper gives an overview of the Medipix2 x-ray detector and its use in medical imaging, with the MARS-CT scanner (MARS, Medipix All Resolution System) as an example. The Medipix2 chip is a photon counting pixel detector with the ability of energy discrimination. It was developed at CERN and is composed of a sensor layer bump bonded to electronics layer. It has 256x256 pixels, each one covering an area of 55x55µm². Furthermore, every pixel can be read out separately. The MARS-CT scanner uses these properties to scan biological objects obtaining multi-energy (spectral) x-ray images with high contrast between materials and high spatial resolution. Charge sharing is the phenomenon by which the electron-hole charge cloud, induced in the sensor layer by an absorbed photon, is detected by a cluster of neighbouring pixels. Each pixel in the cluster generates a signal corresponding to its fraction of the cloud, so the detector will record several photons each of lower energies. This effect has to be considered with the use of Medipix2, because of its small pixels and the hybrid architecture. The effect was measured and a simulation modelled with the aim to reconstruct the spectrum removing the distortion of the detection process.