In this example of image processing we consider the image problem presented in [Hoyer2004].
We used the ORL face database composed of 400 images of size 112 x 92. There are 40 persons, 10 images per each person. The images were taken at different times, lighting and facial expressions. The faces are in an upright position in frontal view, with a slight left-right rotation. In example we performed factorization on reduced face images by constructing a matrix of shape 2576 (pixels) x 400 (faces) and on original face images by constructing a matrix of shape 10304 (pixels) x 400 (faces). To avoid too large values, the data matrix is divided by 100. Indeed, this division does not has any major impact on performance of the MF methods.
Note
The ORL face images database used in this example is included in the datasets and does not need to be downloaded. However, download links are listed in the datasets. To run the example, the ORL face images must exist in the ORL_faces directory under datasets.
We experimented with the Standard NMF - Euclidean, LSNMF and PSMF factorization methods to learn the basis images from the ORL database. The number of bases is 25. In [Lee1999] Lee and Seung showed that Standard NMF (Euclidean or divergence) found a parts-based representation when trained on face images from CBCL database. However, applying NMF to the ORL data set, in which images are not as well aligned, a global decomposition emerges. To compare, this example applies different MF methods to the face images data set. Applying MF methods with sparseness constraint, namely PSMF, the resulting bases are not global, but instead give spatially localized representations, as can be seen from the figure. Similar conclusions are published in [Hoyer2004]. Setting a high sparseness value for the basis images results in a local representation.
Note
It is worth noting that sparseness constraints do not always lead to local solutions. Global solutions can be obtained by forcing low sparseness on basis matrix and high sparseness on coefficient matrix - forcing each coefficient to represent as much of the image as possible.
To run the example simply type:
python orl_images.py
or call the module’s function:
import nimfa.examples
nimfa.examples.orl_images.run()
Note
This example uses matplotlib library for producing visual interpretation of basis vectors. It uses PIL library for displaying face images.
Perform LSNMF factorization on the ORL faces data matrix.
Return basis and mixture matrices of the fitted factorization model.
Parameters: | V (numpy.matrix) – The ORL faces data matrix. |
---|
Plot basis vectors.
Parameters: | W (numpy.matrix) – Basis matrix of the fitted factorization model. |
---|
Preprocess ORL faces data matrix as Stan Li, et. al.
Return normalized and preprocessed data matrix.
Parameters: | V (numpy.matrix) – The ORL faces data matrix. |
---|
Read face image data from the ORL database. The matrix’s shape is 2576 (pixels) x 400 (faces).
Step through each subject and each image. Reduce the size of the images by a factor of 0.5.
Return the ORL faces data matrix.
Run LSNMF on ORL faces data set.