1. A pattern processing device comprising: an input unit to input an input image containing a plurality of pattern elements; an extraction unit that calculates edge intensities of pixels from the input image so as to extract edge pixels and determines, for each extracted edge pixel, gradient direction of brightness gradient of the edge pixel; an evaluation unit that determines for said each extracted edge pixel, a first threshold value set to the extracted edge pixel, and obtains evaluation values for determining whether the pixels from the input image are foreground pixels or background pixels, based on comparison result between (i) the first threshold value corresponding to the respective edge pixels and (ii) pixel values of pixels contained in vicinity regions of the edge pixels, the first threshold value of the extracted edge pixel being determined based on the gradient directions of the brightness gradient of the edge pixel; a binarization determining unit that determines whether the pixels are the foreground pixels or the background pixels by comparing the evaluation values with a predetermined second threshold, and a coupling component extraction unit that extracts pixel coupling components obtained by coupling the pixels adjacent in any direction among the pixels determined to be the foreground pixels.