The present invention relates to an apparatus (10) for counting X-ray photons (12, 14). The apparatus (10) comprises a sensor (16) adapted to convert a photon (12, 14) into a charge pulse, a processing element (18) adapted to convert the charge pulse (51) into an electrical pulse (53) and a first discriminator (20) adapted to compare the electrical pulse (53) against a first threshold (TH1) and to output an event (55) if the first threshold (TH1) is exceeded. A first counter (22) counts these events (55), unless counting is inhibited by a first gating element (24). The first gating element (24) is activated when the first discriminator (20) outputs the event (55), and it is deactivated, when the processing of a photon (12, 14) is found to be complete or about to be completed by a measurement or by the knowledge about the time that it takes to process a photon (12, 14) in the processing element (18). By activating and deactivating the first counter (22) pile-up events, i.e. pile-up of multiple electrical pulses (53), can be addressed. The invention also relates to a corresponding imaging device and a corresponding method.