Skip to content

Commit

Permalink
Eigenfaces tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
jan authored and jan committed Apr 22, 2017
1 parent 5536700 commit 90142b5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
4 changes: 3 additions & 1 deletion docs/tutorial.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Tutorials
================
.. toctree::
:maxdepth: 2

coming soon!
Eigenfaces<tutorials/eigenfaces.rst>
30 changes: 27 additions & 3 deletions examples/eigenfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
# Import PCA, numpy, input output functions, and visualization functions
import numpy as numx
# Import PCA, numpy, input output module, and visualization module
from pydeep.preprocessing import PCA
import numpy as numx
import pydeep.misc.io as io
import pydeep.misc.visualization as vis

# Set the random seed (optional, if stochastic processes are involved we always get the same results)
numx.random.seed(42)

# Load the data
data = io.load_olivetti_faces(path='../../../data/olivettifaces.mat')
data = io.load_olivetti_faces(path='../../data/olivettifaces.mat')

# Specify image width and height for displaying
width = height = 64
Expand Down Expand Up @@ -82,5 +82,29 @@
vis.ylim(0, 1)
vis.xlim(0, 400)

# Show the first 100 Face images reconstructed from 50 principal components
recon = pca.unproject(pca.project(data[0:100], num_components=50)).T
images = vis.tile_matrix_rows(matrix=recon,
tile_width=width,
tile_height=height,
num_tiles_x=10,
num_tiles_y=10,
border_size=1,
normalized=True)
vis.imshow_matrix(matrix=images,
windowtitle='First 100 Face images reconstructed from 50 principal components')

# Show the first 100 Face images reconstructed from 120 principal components
recon = pca.unproject(pca.project(data[0:100], num_components=200)).T
images = vis.tile_matrix_rows(matrix=recon,
tile_width=width,
tile_height=height,
num_tiles_x=10,
num_tiles_y=10,
border_size=1,
normalized=True)
vis.imshow_matrix(matrix=images,
windowtitle='First 100 Face images reconstructed from 200 principal components')

# Show all windows.
vis.show()
2 changes: 1 addition & 1 deletion examples/ica_on_natural_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
numx.random.seed(42)

# Load the data
data = io.load_natural_image_patches('../../../data/NaturalImage.mat')
data = io.load_natural_image_patches('../../data/NaturalImage.mat')

# Specify image width and height for displaying
width = height = 14
Expand Down

0 comments on commit 90142b5

Please sign in to comment.