We develop an optimization algorithm, using simulated annealing for the quantification of patterns in astronomical data based on techniques developed for robotic vision applications. The methodology falls in the category of cost minimization algorithms and it is based on user-determined interaction – among the pattern elements – criteria that define the properties of the sought structures. We applied the algorithm on a large variety of mock images and we constrained the free parameters; α and k, which express the amount of noise in the image and how strictly the algorithm seeks for cocircular structures, respectively. We find that the two parameters are interrelated and also that, independently of the pattern properties, an appropriate selection for most of the images would be log k = −2 and 0 < α ≲ 0.04. The width of the effective α-range, for different values of k, is reduced when more interaction coefficients are taken into account for the definition of the patterns of interest. Finally, we applied the algorithm on N-body simulation dark-matter halo data and on the HST image of the lensing Abell 2218 cluster to conclude that this versatile technique could be applied for the quantification of structure and for identifying coherence in astronomical patterns.