A pattern processing apparatus includes an acquisition unit, an adjacent element identification unit, a connection unit, and an assigning unit. The acquisition unit acquires a pattern image in which pattern elements are arrayed in a grid, together with coordinate information of the pattern elements. The adjacent element identification unit identifies, for each of the pattern elements thus acquired, adjacent elements, in at least two directions, each having the shortest distance to the each of the pattern elements. The distances between the each of the pattern elements and other pattern elements are calculated using the coordinate information. The connection unit connects and groups, as a connected component, the pattern elements that are adjacent to one another. The assigning unit assigns position information in the array in order from the pattern element which is a starting point, among the pattern elements included in the connected component, according to a predetermined regularity.