1. An image processing apparatus comprising: a processor coupled to a memory; a selection unit configured to select at least a pixel that is different from a pixel of interest in an image based on a similarity between a pixel value of the pixel different from the pixel of interest and a pixel value of the pixel of interest; a pixel number setting unit configured to set a number of pixels to be selected by the selection unit; a determination unit configured to determine, from a pixel selected by the selection unit and based on whether a number of pixels selected by the selection unit has reached the number of pixels set by the pixel number setting unit, at least a pixel to be used in predetermined processing that uses at least a pixel value of a pixel different from the pixel of interest; and a processing unit configured to perform the predetermined processing on the pixel of interest, wherein the processing unit performs the predetermined processing on the pixel of interest using a pixel value of the pixel determined by the determination unit, and wherein at least one of the selection unit, the pixel number setting unit, the determination unit, and the processing unit are implemented by the processor.