A semiconductor based photon counting detector comprising a substrate (11) of semiconductor material; a detector bias voltage supply (12) for applying a detector bias voltage over the substrate, each time during a data acquisition period (t1); a readout arrangement (13) for repetitively reading out data indicative of charges freed in, and transported through, the substrate (11) in response to photons being absorbed, each time during a readout period (t2) following a data acquisition period, wherein the data contain number of charge pulses of photons being absorbed; an external light source (15) for exposing the substrate for light to enable trapped charge carriers to escape from defect levels in the substrate; and a control device (14) operatively connected to the detector bias voltage supply, the readout arrangement, and the external light source. The control device (14) is configured to control the detector bias voltage supply to switch off the detector bias voltage over the substrate and the external light