<s> '''<STR_LIT>''' <EOL> import numpy as np <EOL> import scipy . signal <EOL> conv = scipy . signal . convolve <EOL> class V1Processing : <EOL> def __init__ ( self , params , featsel ) : <EOL> '''<STR_LIT>''' <EOL> self . params = params <EOL> self . featsel = featsel <EOL> def extractFromImage ( self , im ) : <EOL> '''<STR_LIT>''' <EOL> mat = im . asMatrix3D ( ) <EOL> mat = mat . transpose ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:0> ) ) <EOL> out = v1like_fromarray ( mat , self . params ) <EOL> return out <EOL> class MinMaxError ( Exception ) : pass <EOL> V1LIKE_PARAMS_A = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:3> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : ( <NUM_LIT:3> , <NUM_LIT:3> ) , <EOL> '<STR_LIT>' : <NUM_LIT:1.0> , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : ( <NUM_LIT> , <NUM_LIT> ) , <EOL> '<STR_LIT>' : [ o * np . pi / <NUM_LIT:16> for o in xrange ( <NUM_LIT:16> ) ] , <EOL> '<STR_LIT>' : [ <NUM_LIT:1.> / n for n in [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:11> , <NUM_LIT> ] ] , <EOL> '<STR_LIT>' : [ <NUM_LIT:0> ] , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : ( <NUM_LIT:3> , <NUM_LIT:3> ) , <EOL> '<STR_LIT>' : <NUM_LIT:1.0> , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : ( <NUM_LIT:30> , <NUM_LIT:30> ) , <EOL> } , <EOL> } <EOL> V1LIKE_FEATURES_A = { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> } <EOL> def gray_convert ( arr ) : <EOL> out = <NUM_LIT> * arr [ : , : , <NUM_LIT:0> ] + <NUM_LIT> * arr [ : , : , <NUM_LIT:1> ] + <NUM_LIT> * arr [ : , : , <NUM_LIT:2> ] <EOL> return out <EOL> def opp_convert ( arr ) : <EOL> out = np . empty_like ( arr ) <EOL> out [ : , : , <NUM_LIT:0> ] = arr [ : , : , <NUM_LIT:0> ] - arr [ : , : , <NUM_LIT:1> ] <EOL> out [ : , : , <NUM_LIT:1> ] = arr [ : , : , <NUM_LIT:2> ] - arr [ : , : , [ <NUM_LIT:0> , <NUM_LIT:1> ] ] . min ( <NUM_LIT:2> ) <EOL> out [ : , : , <NUM_LIT:2> ] = arr . max ( <NUM_LIT:2> ) <EOL> return out <EOL> def oppnorm_convert ( arr , threshold = <NUM_LIT:0.1> ) : <EOL> arr = arr . astype ( '<STR_LIT>' ) <EOL> out = np . empty ( arr . shape [ : <NUM_LIT:2> ] + ( <NUM_LIT:2> , ) , dtype = '<STR_LIT>' ) <EOL> print out . shape <EOL> out [ : , : , <NUM_LIT:0> ] = arr [ : , : , <NUM_LIT:0> ] - arr [ : , : , <NUM_LIT:1> ] <EOL> out [ : , : , <NUM_LIT:1> ] = arr [ : , : , <NUM_LIT:2> ] - arr [ : , : , [ <NUM_LIT:0> , <NUM_LIT:1> ] ] . min ( <NUM_LIT:2> ) <EOL> denom = arr . max ( <NUM_LIT:2> ) <EOL> mask = denom < threshold <EOL> out [ : , : , <NUM_LIT:0> ] /= denom <EOL> out [ : , : , <NUM_LIT:1> ] /= denom <EOL> np . putmask ( out [ : , : , <NUM_LIT:0> ] , mask , <NUM_LIT:0> ) <EOL> np . putmask ( out [ : , : , <NUM_LIT:1> ] , mask , <NUM_LIT:0> ) <EOL> return out <EOL> def chrom_convert ( arr ) : <EOL> opp = opp_convert ( arr ) <EOL> out = np . empty_like ( opp [ : , : , [ <NUM_LIT:0> , <NUM_LIT:1> ] ] ) <EOL> rg = opp [ : , : , <NUM_LIT:0> ] <EOL> by = opp [ : , : , <NUM_LIT:1> ] <EOL> intensity = opp [ : , : , <NUM_LIT:2> ] <EOL> lowi = intensity < <NUM_LIT:0.1> * intensity . max ( ) <EOL> rg [ lowi ] = <NUM_LIT:0> <EOL> by [ lowi ] = <NUM_LIT:0> <EOL> denom = intensity <EOL> denom [ denom == <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> out [ : , : , <NUM_LIT:0> ] = rg / denom <EOL> out [ : , : , <NUM_LIT:1> ] = by / denom <EOL> return out <EOL> def rg2_convert ( arr ) : <EOL> out = np . empty_like ( arr [ : , : , [ <NUM_LIT:0> , <NUM_LIT:1> ] ] ) <EOL> red = arr [ : , : , <NUM_LIT:0> ] <EOL> green = arr [ : , : , <NUM_LIT:1> ] <EOL> intensity = arr . mean ( <NUM_LIT:2> ) <EOL> lowi = intensity < <NUM_LIT:0.1> * intensity . max ( ) <EOL> arr [ lowi ] = <NUM_LIT:0> <EOL> denom = arr . sum ( <NUM_LIT:2> ) <EOL> denom [ denom == <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> out [ : , : , <NUM_LIT:0> ] = red / denom <EOL> out [ : , : , <NUM_LIT:1> ] = green / denom <EOL> return out <EOL> def hsv_convert ( arr ) : <EOL> """<STR_LIT>""" <EOL> arr = arr . astype ( "<STR_LIT>" ) <EOL> out = np . empty_like ( arr ) <EOL> arr_max = arr . max ( - <NUM_LIT:1> ) <EOL> delta = arr . ptp ( - <NUM_LIT:1> ) <EOL> s = delta / arr_max <EOL> s [ delta == <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> idx = ( arr [ : , : , <NUM_LIT:0> ] == arr_max ) <EOL> out [ idx , <NUM_LIT:0> ] = ( arr [ idx , <NUM_LIT:1> ] - arr [ idx , <NUM_LIT:2> ] ) / delta [ idx ] <EOL> idx = ( arr [ : , : , <NUM_LIT:1> ] == arr_max ) <EOL> out [ idx , <NUM_LIT:0> ] = <NUM_LIT> + ( arr [ idx , <NUM_LIT:2> ] - arr [ idx , <NUM_LIT:0> ] ) / delta [ idx ] <EOL> idx = ( arr [ : , : , <NUM_LIT:2> ] == arr_max ) <EOL> out [ idx , <NUM_LIT:0> ] = <NUM_LIT> + ( arr [ idx , <NUM_LIT:0> ] - arr [ idx , <NUM_LIT:1> ] ) / delta [ idx ] <EOL> out [ : , : , <NUM_LIT:0> ] = ( out [ : , : , <NUM_LIT:0> ] / <NUM_LIT> ) % <NUM_LIT:1.0> <EOL> out [ : , : , <NUM_LIT:1> ] = s <EOL> out [ : , : , <NUM_LIT:2> ] = arr_max <EOL> out [ np . isnan ( out ) ] = <NUM_LIT:0> <EOL> return out <EOL> def rgb_convert ( arr ) : <EOL> if arr . ndim == <NUM_LIT:2> or arr . shape [ <NUM_LIT:2> ] == <NUM_LIT:1> : <EOL> arr_new = np . empty ( arr . shape [ : <NUM_LIT:2> ] + ( <NUM_LIT:3> , ) , dtype = "<STR_LIT>" ) <EOL> arr_new [ : , : , <NUM_LIT:0> ] = arr . copy ( ) <EOL> arr_new [ : , : , <NUM_LIT:1> ] = arr . copy ( ) <EOL> arr_new [ : , : , <NUM_LIT:2> ] = arr . copy ( ) <EOL> arr = arr_new <EOL> return arr <EOL> def fastnorm ( x ) : <EOL> """<STR_LIT>""" <EOL> xv = x . ravel ( ) <EOL> return np . dot ( xv , xv ) ** ( <NUM_LIT:1> / <NUM_LIT> ) <EOL> def gabor2d ( gw , gh , gx0 , gy0 , wfreq , worient , wphase , shape ) : <EOL> """<STR_LIT>""" <EOL> height , width = shape <EOL> y , x = np . mgrid [ <NUM_LIT:0> : height , <NUM_LIT:0> : width ] <EOL> X = x * np . cos ( worient ) * wfreq <EOL> Y = y * np . sin ( worient ) * wfreq <EOL> env = np . exp ( - np . pi * ( ( ( x - gx0 ) ** <NUM_LIT> / gw ** <NUM_LIT> ) + ( ( y - gy0 ) ** <NUM_LIT> / gh ** <NUM_LIT> ) ) ) <EOL> wave = np . exp ( <NUM_LIT> * ( <NUM_LIT:2> * np . pi * ( X + Y ) + wphase ) ) <EOL> gabor = np . real ( env * wave ) <EOL> gabor -= gabor . mean ( ) <EOL> gabor /= fastnorm ( gabor ) <EOL> return gabor <EOL> def sresample ( src , outshape ) : <EOL> """<STR_LIT>""" <EOL> inh , inw = src . shape [ : <NUM_LIT:2> ] <EOL> outh , outw = outshape <EOL> hslice = ( np . arange ( outh ) * ( inh - <NUM_LIT:1.> ) / ( outh - <NUM_LIT:1.> ) ) . round ( ) . astype ( int ) <EOL> wslice = ( np . arange ( outw ) * ( inw - <NUM_LIT:1.> ) / ( outw - <NUM_LIT:1.> ) ) . round ( ) . astype ( int ) <EOL> hout = src [ hslice , : ] [ : , wslice ] <EOL> return hout . copy ( ) <EOL> def v1like_pool ( hin , conv_mode , lsum_ksize , outshape = None , order = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> order = float ( order ) <EOL> assert ( order >= <NUM_LIT:1> ) <EOL> if lsum_ksize is not None : <EOL> hin_h , hin_w , hin_d = hin . shape <EOL> dtype = hin . dtype <EOL> if conv_mode == "<STR_LIT>" : <EOL> aux_shape = hin_h - lsum_ksize + <NUM_LIT:1> , hin_w - lsum_ksize + <NUM_LIT:1> , hin_d <EOL> aux = np . empty ( aux_shape , dtype ) <EOL> else : <EOL> aux = np . empty ( hin . shape , dtype ) <EOL> k1d = np . ones ( ( lsum_ksize ) , '<STR_LIT:f>' ) <EOL> krow = k1d [ None , : ] <EOL> kcol = k1d [ : , None ] <EOL> for d in xrange ( aux . shape [ <NUM_LIT:2> ] ) : <EOL> if order == <NUM_LIT:1> : <EOL> aux [ : , : , d ] = conv ( conv ( hin [ : , : , d ] , krow , conv_mode ) , kcol , conv_mode ) <EOL> else : <EOL> aux [ : , : , d ] = conv ( conv ( hin [ : , : , d ] ** order , krow , conv_mode ) , kcol , conv_mode ) ** ( <NUM_LIT:1.> / order ) <EOL> else : <EOL> aux = hin <EOL> if outshape is None or outshape == aux . shape : <EOL> hout = aux <EOL> else : <EOL> hout = sresample ( aux , outshape ) <EOL> return hout <EOL> fft_cache = { } <EOL> def v1like_filter ( hin , conv_mode , filterbank , use_cache = False ) : <EOL> """<STR_LIT>""" <EOL> nfilters = len ( filterbank ) <EOL> filt0 = filterbank [ <NUM_LIT:0> ] <EOL> fft_shape = np . array ( hin . shape ) + np . array ( filt0 . shape ) - <NUM_LIT:1> <EOL> hin_fft = np . fft . fftn ( hin , fft_shape ) <EOL> if conv_mode == "<STR_LIT>" : <EOL> hout_shape = list ( np . array ( hin . shape [ : <NUM_LIT:2> ] ) - np . array ( filt0 . shape [ : <NUM_LIT:2> ] ) + <NUM_LIT:1> ) + [ nfilters ] <EOL> hout_new = np . empty ( hout_shape , '<STR_LIT:f>' ) <EOL> begy = filt0 . shape [ <NUM_LIT:0> ] <EOL> endy = begy + hout_shape [ <NUM_LIT:0> ] <EOL> begx = filt0 . shape [ <NUM_LIT:1> ] <EOL> endx = begx + hout_shape [ <NUM_LIT:1> ] <EOL> elif conv_mode == "<STR_LIT>" : <EOL> hout_shape = hin . shape [ : <NUM_LIT:2> ] + ( nfilters , ) <EOL> hout_new = np . empty ( hout_shape , '<STR_LIT:f>' ) <EOL> begy = filt0 . shape [ <NUM_LIT:0> ] / <NUM_LIT:2> <EOL> endy = begy + hout_shape [ <NUM_LIT:0> ] <EOL> begx = filt0 . shape [ <NUM_LIT:1> ] / <NUM_LIT:2> <EOL> endx = begx + hout_shape [ <NUM_LIT:1> ] <EOL> else : <EOL> raise NotImplementedError <EOL> for i in xrange ( nfilters ) : <EOL> filt = filterbank [ i ] <EOL> if use_cache : <EOL> key = ( filt . tostring ( ) , tuple ( fft_shape ) ) <EOL> if key in fft_cache : <EOL> filt_fft = fft_cache [ key ] <EOL> else : <EOL> filt_fft = scipy . fft . fftn ( filt , fft_shape ) <EOL> fft_cache [ key ] = filt_fft <EOL> else : <EOL> filt_fft = np . fft . fftn ( filt , fft_shape ) <EOL> res_fft = np . fft . ifftn ( hin_fft * filt_fft ) <EOL> res_fft = res_fft [ begy : endy , begx : endx ] <EOL> hout_new [ : , : , i ] = np . real ( res_fft ) <EOL> hout = hout_new <EOL> return hout <EOL> filt_l = None <EOL> def get_gabor_filters ( params ) : <EOL> """<STR_LIT>""" <EOL> global filt_l <EOL> if filt_l is not None : <EOL> return filt_l <EOL> fh , fw = params [ '<STR_LIT>' ] <EOL> orients = params [ '<STR_LIT>' ] <EOL> freqs = params [ '<STR_LIT>' ] <EOL> phases = params [ '<STR_LIT>' ] <EOL> xc = fw / <NUM_LIT:2> <EOL> yc = fh / <NUM_LIT:2> <EOL> filt_l = [ ] <EOL> for freq in freqs : <EOL> for orient in orients : <EOL> for phase in phases : <EOL> filt = gabor2d ( xc , yc , xc , yc , <EOL> freq , orient , phase , <EOL> ( fw , fh ) ) <EOL> filt_l += [ filt ] <EOL> return filt_l <EOL> def v1like_norm ( hin , conv_mode , kshape , threshold ) : <EOL> """<STR_LIT>""" <EOL> eps = <NUM_LIT> <EOL> kh , kw = kshape <EOL> dtype = hin . dtype <EOL> hsrc = hin [ : ] . copy ( ) <EOL> hin_h , hin_w , hin_d = hin . shape <EOL> hout_h = hin_h <EOL> hout_w = hin_w <EOL> if conv_mode != "<STR_LIT>" : <EOL> hout_h = hout_h - kh + <NUM_LIT:1> <EOL> hout_w = hout_w - kw + <NUM_LIT:1> <EOL> hout_d = hin_d <EOL> hout = np . empty ( ( hout_h , hout_w , hout_d ) , '<STR_LIT>' ) <EOL> hin_d = hin . shape [ - <NUM_LIT:1> ] <EOL> kshape3d = list ( kshape ) + [ hin_d ] <EOL> ker = np . ones ( kshape3d , dtype = dtype ) <EOL> size = ker . size <EOL> hsq = hsrc ** <NUM_LIT> <EOL> kerH = ker [ : , <NUM_LIT:0> , <NUM_LIT:0> ] [ : , None ] <EOL> kerW = ker [ <NUM_LIT:0> , : , <NUM_LIT:0> ] [ None , : ] <EOL> kerD = ker [ <NUM_LIT:0> , <NUM_LIT:0> , : ] [ None , None , : ] <EOL> hssq = conv ( <EOL> conv ( <EOL> conv ( hsq , kerD , '<STR_LIT>' ) [ : , : , <NUM_LIT:0> ] . astype ( dtype ) , <EOL> kerW , <EOL> conv_mode ) , <EOL> kerH , <EOL> conv_mode ) . astype ( dtype ) <EOL> hssq = hssq [ : , : , None ] <EOL> ys = kh / <NUM_LIT:2> <EOL> xs = kw / <NUM_LIT:2> <EOL> hout_h , hout_w , hout_d = hout . shape [ - <NUM_LIT:3> : ] <EOL> hs = hout_h <EOL> ws = hout_w <EOL> hsum = conv ( <EOL> conv ( <EOL> conv ( hsrc , <EOL> kerD , '<STR_LIT>' ) [ : , : , <NUM_LIT:0> ] . astype ( dtype ) , <EOL> kerW , <EOL> conv_mode ) , <EOL> kerH , <EOL> conv_mode ) . astype ( dtype ) <EOL> hsum = hsum [ : , : , None ] <EOL> if conv_mode == '<STR_LIT>' : <EOL> hnum = hsrc - ( hsum / size ) <EOL> else : <EOL> hnum = hsrc [ ys : ys + hs , xs : xs + ws ] - ( hsum / size ) <EOL> val = ( hssq - ( hsum ** <NUM_LIT> ) / size ) <EOL> val [ val < <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> hdiv = val ** ( <NUM_LIT:1.> / <NUM_LIT:2> ) + eps <EOL> np . putmask ( hdiv , hdiv < ( threshold + eps ) , <NUM_LIT:1.> ) <EOL> result = ( hnum / hdiv ) <EOL> hout [ : ] = result <EOL> return hout <EOL> def v1like_fromarray ( arr , params ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' not in params : <EOL> params [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if '<STR_LIT>' not in params : <EOL> params [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> arr = np . atleast_3d ( arr ) <EOL> smallest_edge = min ( arr . shape [ : <NUM_LIT:2> ] ) <EOL> rep = params <EOL> preproc_lsum = rep [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if preproc_lsum is None : <EOL> preproc_lsum = <NUM_LIT:1> <EOL> smallest_edge -= ( preproc_lsum - <NUM_LIT:1> ) <EOL> normin_kshape = rep [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> smallest_edge -= ( normin_kshape [ <NUM_LIT:0> ] - <NUM_LIT:1> ) <EOL> filter_kshape = rep [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> smallest_edge -= ( filter_kshape [ <NUM_LIT:0> ] - <NUM_LIT:1> ) <EOL> normout_kshape = rep [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> smallest_edge -= ( normout_kshape [ <NUM_LIT:0> ] - <NUM_LIT:1> ) <EOL> pool_lsum = rep [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> smallest_edge -= ( pool_lsum - <NUM_LIT:1> ) <EOL> arrh , arrw , _ = arr . shape <EOL> if smallest_edge <= <NUM_LIT:0> and rep [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> if arrh > arrw : <EOL> new_w = arrw - smallest_edge + <NUM_LIT:1> <EOL> new_h = int ( np . round ( <NUM_LIT:1.> * new_w * arrh / arrw ) ) <EOL> print new_w , new_h <EOL> raise <EOL> elif arrh < arrw : <EOL> new_h = arrh - smallest_edge + <NUM_LIT:1> <EOL> new_w = int ( np . round ( <NUM_LIT:1.> * new_h * arrw / arrh ) ) <EOL> print new_w , new_h <EOL> raise <EOL> else : <EOL> pass <EOL> assert min ( arr . shape [ : <NUM_LIT:2> ] ) > <NUM_LIT:0> <EOL> orig_imga = arr . astype ( "<STR_LIT>" ) [ : , : , : <NUM_LIT:3> ] <EOL> if orig_imga . shape [ <NUM_LIT:2> ] == <NUM_LIT:3> and ( orig_imga [ : , : , <NUM_LIT:0> ] - orig_imga . mean ( <NUM_LIT:2> ) < <NUM_LIT:0.1> * orig_imga . max ( ) ) . all ( ) and ( orig_imga [ : , : , <NUM_LIT:1> ] - orig_imga . mean ( <NUM_LIT:2> ) < <NUM_LIT:0.1> * orig_imga . max ( ) ) . all ( ) and ( orig_imga [ : , : , <NUM_LIT:2> ] - orig_imga . mean ( <NUM_LIT:2> ) < <NUM_LIT:0.1> * orig_imga . max ( ) ) . all ( ) : <EOL> orig_imga = np . atleast_3d ( orig_imga [ : , : , <NUM_LIT:0> ] ) <EOL> if orig_imga . min ( ) == orig_imga . max ( ) : <EOL> raise MinMaxError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( orig_imga . min ( ) , orig_imga . max ( ) ) <EOL> ) <EOL> orig_imga -= orig_imga . min ( ) <EOL> orig_imga /= orig_imga . max ( ) <EOL> if orig_imga . ndim == <NUM_LIT:2> or orig_imga . shape [ <NUM_LIT:2> ] == <NUM_LIT:1> : <EOL> orig_imga_new = np . empty ( orig_imga . shape [ : <NUM_LIT:2> ] + ( <NUM_LIT:3> , ) , dtype = "<STR_LIT>" ) <EOL> orig_imga . shape = orig_imga_new [ : , : , <NUM_LIT:0> ] . shape <EOL> orig_imga_new [ : , : , <NUM_LIT:0> ] = <NUM_LIT> * orig_imga <EOL> orig_imga_new [ : , : , <NUM_LIT:1> ] = <NUM_LIT> * orig_imga <EOL> orig_imga_new [ : , : , <NUM_LIT:2> ] = <NUM_LIT> * orig_imga <EOL> orig_imga = orig_imga_new <EOL> if params [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> orig_imga_conv = orig_imga <EOL> elif params [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> orig_imga_conv = rg2_convert ( orig_imga ) <EOL> elif params [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> orig_imga_conv = gray_convert ( orig_imga ) <EOL> orig_imga_conv . shape = orig_imga_conv . shape + ( <NUM_LIT:1> , ) <EOL> elif params [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> orig_imga_conv = opp_convert ( orig_imga ) <EOL> elif params [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> orig_imga_conv = oppnorm_convert ( orig_imga ) <EOL> elif params [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> orig_imga_conv = chrom_convert ( orig_imga ) <EOL> elif params [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> orig_imga_conv = hsv_convert ( orig_imga ) <EOL> else : <EOL> raise ValueError , "<STR_LIT>" <EOL> for cidx in xrange ( orig_imga_conv . shape [ <NUM_LIT:2> ] ) : <EOL> imga0 = orig_imga_conv [ : , : , cidx ] <EOL> assert ( imga0 . min ( ) != imga0 . max ( ) ) <EOL> if '<STR_LIT>' in params [ '<STR_LIT>' ] and params [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> imga0 = imga0 [ : , : : - <NUM_LIT:1> ] <EOL> if '<STR_LIT>' in params [ '<STR_LIT>' ] and params [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> imga0 = imga0 [ : : - <NUM_LIT:1> , : ] <EOL> lsum_ksize = params [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> conv_mode = params [ '<STR_LIT>' ] <EOL> if lsum_ksize is not None : <EOL> k = np . ones ( ( lsum_ksize ) , '<STR_LIT:f>' ) / lsum_ksize <EOL> imga0 = conv ( conv ( imga0 , k [ np . newaxis , : ] , conv_mode ) , <EOL> k [ : , np . newaxis ] , conv_mode ) <EOL> if '<STR_LIT>' not in params [ '<STR_LIT>' ] or params [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> imga0 -= imga0 . mean ( ) <EOL> if imga0 . std ( ) != <NUM_LIT:0> : <EOL> imga0 /= imga0 . std ( ) <EOL> imga1 = v1like_norm ( imga0 [ : , : , np . newaxis ] , conv_mode , ** params [ '<STR_LIT>' ] ) <EOL> filt_l = get_gabor_filters ( params [ '<STR_LIT>' ] ) <EOL> imga2 = v1like_filter ( imga1 [ : , : , <NUM_LIT:0> ] , conv_mode , filt_l ) <EOL> minout = params [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> maxout = params [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> imga3 = imga2 . clip ( minout , maxout ) <EOL> imga4 = v1like_norm ( imga3 , conv_mode , ** params [ '<STR_LIT>' ] ) <EOL> if "<STR_LIT>" in params and params [ "<STR_LIT>" ] : <EOL> imga4 = ( imga4 . max ( <NUM_LIT:2> ) [ : , : , None ] == imga4 ) <EOL> imga5 = v1like_pool ( imga4 , conv_mode , ** params [ '<STR_LIT>' ] ) <EOL> output = imga5 <EOL> return output </s>
