1. A pattern processing apparatus comprising: an acquisition unit configured to acquire a pattern image in which a plurality of pattern elements are arrayed in a grid, together with coordinate information of the pattern elements; an adjacent element identification unit configured to identify, for each pattern element of the acquired pattern elements, adjacent elements, in at least two directions, each adjacent element having a shortest distance to the pattern element in one of the at least two directions, wherein distances between each of the pattern elements and other pattern elements are calculated using the coordinate information; a connection unit configured to connect and group, as a connected component, the pattern elements that are identified as adjacent to one another; and an assigning unit configured to assign position information in the connected component in order from a starting pattern element which is a starting point, among the pattern elements included in the connected component, according to a predetermined regularity.