On the vertex detector of the International Linear Collider, a large number of hits are generated by the charged particles coming from the beam background. These charged particles produce large angles of incidence and generate elongated clusters. The CMOS pixel sensor (CPS) which would contain on-chip artificial neural networks could tag and remove these clusters to reduce the data flow of the detector system. The clustering procedure is the first step of data preprocessing. The conventional clustering algorithm is not suitable for on-chip integration since it requires sequential and iterative processing. In this article, a 2-D real-time clustering algorithm is proposed. The clustering algorithm is tested by 4500 frames of pixel values (12 bit/pixel) from MIMOSA-18. The clustering algorithm is implemented using Very High-Speed Integrated Circuit Hardware Description Language (VHDL), synthesized for different windows, multiplexers, and analog-to-digital converter (ADC) resolution. Power consumption and the occupied surface of the clustering implementation are presented. This implementation provides a possibility to integrate the clustering procedure into a CPS.