1. An image processing apparatus for determining a pixel value of a target pixel by a weighted mean of a plurality of reference pixels in image data, comprising a processor and a memory storing instructions which, when executed by the processor, cause the processor to function as: a derivation unit configured to derive a weight for each of the reference pixels, based on similarity between a target region associated with the target pixel and a reference region associated with the reference pixels; and a weighted mean processing unit configured to perform weighted mean processing by calculating a sum of products of pixel values of the plurality of reference pixels and the weights corresponding to the reference pixels, respectively, derived by the derivation unit, wherein the derivation unit derives a weight for the target pixel to be used for the sum of products calculated by the weighted mean processing unit as 0, and the weighted mean processing unit calculates a result of the weighted mean processing using the sum of products by using the weights derived by the derivation unit.