<s> from facerec . normalization import minmax <EOL> import os as os <EOL> import numpy as np <EOL> import matplotlib . pyplot as plt <EOL> import matplotlib . cm as cm <EOL> try : <EOL> from PIL import Image <EOL> except ImportError : <EOL> import Image <EOL> import math as math <EOL> def create_font ( fontname = '<STR_LIT>' , fontsize = <NUM_LIT:10> ) : <EOL> return { '<STR_LIT>' : fontname , '<STR_LIT>' : fontsize } <EOL> def plot_gray ( X , sz = None , filename = None ) : <EOL> if not sz is None : <EOL> X = X . reshape ( sz ) <EOL> X = minmax ( I , <NUM_LIT:0> , <NUM_LIT:255> ) <EOL> fig = plt . figure ( ) <EOL> implot = plt . imshow ( np . asarray ( Ig ) , cmap = cm . gray ) <EOL> if filename is None : <EOL> plt . show ( ) <EOL> else : <EOL> fig . savefig ( filename , format = "<STR_LIT>" , transparent = False ) <EOL> def plot_eigenvectors ( eigenvectors , num_components , sz , filename = None , start_component = <NUM_LIT:0> , rows = None , cols = None , title = "<STR_LIT>" , color = True ) : <EOL> if ( rows is None ) or ( cols is None ) : <EOL> rows = cols = int ( math . ceil ( np . sqrt ( num_components ) ) ) <EOL> num_components = np . min ( num_components , eigenvectors . shape [ <NUM_LIT:1> ] ) <EOL> fig = plt . figure ( ) <EOL> for i in range ( start_component , num_components ) : <EOL> vi = eigenvectors [ <NUM_LIT:0> : , i ] . copy ( ) <EOL> vi = minmax ( np . asarray ( vi ) , <NUM_LIT:0> , <NUM_LIT:255> , dtype = np . uint8 ) <EOL> vi = vi . reshape ( sz ) <EOL> ax0 = fig . add_subplot ( rows , cols , ( i - start_component ) + <NUM_LIT:1> ) <EOL> plt . setp ( ax0 . get_xticklabels ( ) , visible = False ) <EOL> plt . setp ( ax0 . get_yticklabels ( ) , visible = False ) <EOL> plt . title ( "<STR_LIT>" % ( title , i ) , create_font ( '<STR_LIT>' , <NUM_LIT:10> ) ) <EOL> if color : <EOL> implot = plt . imshow ( np . asarray ( vi ) ) <EOL> else : <EOL> implot = plt . imshow ( np . asarray ( vi ) , cmap = cm . grey ) <EOL> if filename is None : <EOL> fig . show ( ) <EOL> else : <EOL> fig . savefig ( filename , format = "<STR_LIT>" , transparent = False ) <EOL> def subplot ( title , images , rows , cols , sptitle = "<STR_LIT>" , sptitles = [ ] , colormap = cm . gray , ticks_visible = True , filename = None ) : <EOL> fig = plt . figure ( ) <EOL> fig . text ( <NUM_LIT> , <NUM_LIT> , title , horizontalalignment = '<STR_LIT>' ) <EOL> for i in xrange ( len ( images ) ) : <EOL> ax0 = fig . add_subplot ( rows , cols , ( i + <NUM_LIT:1> ) ) <EOL> plt . setp ( ax0 . get_xticklabels ( ) , visible = False ) <EOL> plt . setp ( ax0 . get_yticklabels ( ) , visible = False ) <EOL> if len ( sptitles ) == len ( images ) : <EOL> plt . title ( "<STR_LIT>" % ( sptitle , str ( sptitles [ i ] ) ) , create_font ( '<STR_LIT>' , <NUM_LIT:10> ) ) <EOL> else : <EOL> plt . title ( "<STR_LIT>" % ( sptitle , ( i + <NUM_LIT:1> ) ) , create_font ( '<STR_LIT>' , <NUM_LIT:10> ) ) <EOL> plt . imshow ( np . asarray ( images [ i ] ) , cmap = colormap ) <EOL> if filename is None : <EOL> plt . show ( ) <EOL> else : <EOL> fig . savefig ( filename ) </s>
