A detection device comprising: an acquisition unit configured to acquire each pixel value of a captured image (Ia) acquired by imaging an object by an imaging unit, as a target pixel value; a slope calculating unit configured to calculate each slope between adjacent two points on a graph representing a change in pixel values within a predetermined search range starting at a pixel corresponding to each target pixel value; an extremum detecting unit configured to detect extremums of the pixel values based on the slopes; a counting unit configured to count the number of extremums whose pixel value is in a predetermined range among the extremums detected by the extremum detecting unit in the search range; a determination unit configured to, when the number is equal to or larger than a predetermined threshold, determine that a pixel corresponding to the target pixel value is included in an image area of a repeated pattern of the captured image (Ia); a setting unit configured to set a threshold range as the predetermined range based on the pixel value of the extremum detected by the extremum detecting unit outside the search range, wherein the extremum detecting unit detects maximums and minimums of the pixel values based on the slopes, the setting unit sets a first range as the threshold range based on the pixel value of the maximums detected by the extremum detecting unit and sets a second range as the threshold range based on the pixel value of the minimums detected by the extremum detecting unit in the search range, the counting unit counts a first number that is the number of the maximums whose pixel value is in the first range among the maximums detected by the extremum detecting unit and counts a second number that is the number of the minimums whose pixel value is in the second range among the minimums detected by the extremum detecting unit in the search range, and the determination unit determines whether a pixel corresponding to the target pixel value is included in the image area of the repeated pattern based on at least one of the first number and the second number. an acquisition unit configured to acquire each pixel value of a captured image (Ia) acquired by imaging an object by an imaging unit, as a target pixel value; a slope calculating unit configured to calculate each slope between adjacent two points on a graph representing a change in pixel values within a predetermined search range starting at a pixel corresponding to each target pixel value; an extremum detecting unit configured to detect extremums of the pixel values based on the slopes; a counting unit configured to count the number of extremums whose pixel value is in a predetermined range among the extremums detected by the extremum detecting unit in the search range; a determination unit configured to, when the number is equal to or larger than a predetermined threshold, determine that a pixel corresponding to the target pixel value is included in an image area of a repeated pattern of the captured image (Ia); a setting unit configured to set a threshold range as the predetermined range based on the pixel value of the extremum detected by the extremum detecting unit outside the search range, wherein the extremum detecting unit detects maximums and minimums of the pixel values based on the slopes, the setting unit sets a first range as the threshold range based on the pixel value of the maximums detected by the extremum detecting unit and sets a second range as the threshold range based on the pixel value of the minimums detected by the extremum detecting unit in the search range, the counting unit counts a first number that is the number of the maximums whose pixel value is in the first range among the maximums detected by the extremum detecting unit and counts a second number that is the number of the minimums whose pixel value is in the second range among the minimums detected by the extremum detecting unit in the search range, and the determination unit determines whether a pixel corresponding to the target pixel value is included in the image area of the repeated pattern based on at least one of the first number and the second number.