X-ray detection is widely used in various applications. However, to meet the demand for high image quality and high accuracy diagnosis, the raw data increases and imposes challenges for conventional X-ray detection hardware regarding data transmission and power consumption. To tackle these issues, we present a scheme of in-X-ray-detector computing based on CsPbBr3 single-crystal detector with convenient polarity reconfigurability, good linear dynamic range, and robust stability. The detector features a stable trap-free device structure and achieves a high linear dynamic range of 106 dB. As a result, the detector could achieve edge extraction imaging with a data compression ratio of ~50%, and could also be programmed and trained to perform pattern recognition tasks with a high accuracy of 100%. Our research shows that in-X-ray-detector computing can be used in flexible and complex scenarios, making it a promising platform for intelligent X-ray imaging.