In this example of image processing we consider the problem demonstrated in [Lee1999].
We used the CBCL face images database consisting of 2429 face images of size 19 x 19. The facial images consist of frontal views hand aligned in a 19 x 19 grid. Each face image is preprocessed. For each image, the greyscale intensities are first linearly scaled, so that the pixel mean and standard deviation are equal to 0.25, and then clipped to the range [0, 1].
Note
The CBCL face images database used in this example is not included in the datasets. If you wish to perform the CBCL data experiments, start by downloading the images. Download links are listed in the datasets. To run the example, uncompress the data and put it into corresponding data directory, namely the extracted CBCL data set must exist in the CBCL_faces directory under datasets. Once you have the data installed, you are ready to start running the experiments.
We experimented with the following factorization algorithms to learn the basis images from the CBCL database: Standard NMF - Euclidean, LSNMF, SNMF/R and SNMF/L. The number of bases is 49. Random Vcol algorithm is used for factorization initialization. The algorithms mostly converge after less than 50 iterations.
Unlike vector quantization and principal components analysis ([Lee1999]), these algorithms learn a parts-based representations of faces and some also spatially localized representations depending on different types of constraints on basis and mixture matrix. Following are 7 x 7 montages of learned basis images by different factorization algorithms.
To run the example simply type:
python cbcl_images.py
or call the module’s function:
import nimfa.examples
nimfa.examples.cbcl_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 CBCL faces data matrix.
Return basis and mixture matrices of the fitted factorization model.
Parameters: | V (numpy.matrix) – The CBCL faces data matrix. |
---|
Plot basis vectors.
Parameters: | W (numpy.matrix) – Basis matrix of the fitted factorization model. |
---|
Preprocess CBCL faces data matrix as Lee and Seung.
Return normalized and preprocessed data matrix.
Parameters: | V (numpy.matrix) – The CBCL faces data matrix. |
---|
Read face image data from the CBCL database. The matrix’s shape is 361 (pixels) x 2429 (faces).
Step through each subject and each image. Images’ sizes are not reduced.
Return the CBCL faces data matrix.
Run LSNMF on CBCL faces data set.