1. An image processing apparatus comprising: a first computation portion configured to obtain magnitudes of correlations between a first vector having, as elements, pixel values of pixels in a first region containing a first pixel in an image and a plurality of basis vectors; a selection portion configured to select basis vectors from the plurality of basis vectors in accordance with the magnitudes of the correlations; a projection portion configured to select second regions containing second pixels in the image, to obtain a first projection vector by projecting the first vector onto a subspace formed by the selected basis vectors and to obtain a second projection vector for each second region by projecting onto the subspace a second vector in which pixel values of pixels in each second region are arranged; a second computation portion configured to compute, for each second region, a distance between the first projection vector and the second projection vector corresponding to each second region; and a weighted averaging portion configured to weighted average a pixel value of the second pixel with giving larger weights to the second pixel as the distance corresponding to each second region is smaller so as to obtain an output pixel value of the first pixel.