00001 """ 00002 Contains the N-D contourlet transform. 00003 These are the Surfacelet helper functions. 00004 """ 00005 00006 __copyright__ = """ 00007 Copyright 2008 Sean Ross-Ross 00008 """ 00009 __license__ = """ 00010 This file is part of SLIMpy . 00011 00012 SLIMpy is free software: you can redistribute it and/or modify 00013 it under the terms of the GNU Lesser General Public License as published by 00014 the Free Software Foundation, either version 3 of the License, or 00015 (at your option) any later version. 00016 00017 SLIMpy is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 GNU Lesser General Public License for more details. 00021 00022 You should have received a copy of the GNU Lesser General Public License 00023 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>. 00024 """ 00025 00026 import re 00027 00028 00029 """ 00030 n1,n2 and n1out,n2out are the same. If n1 (or n1out) is declared then 00031 you set the space to equal n1 (or n1out). 00032 00033 If beg1,beg2,end1,end2 are declared instead. Then you want to grab the 00034 exsisting space and add these to the being and end of them. 00035 """ 00036 def padHelper(command,space,*spaces): 00037 for cmd in command.kparams.keys(): 00038 if re.match('^n\d+$',cmd): 00039 space[cmd] = command[cmd] 00040 elif re.match('^n\d+out$',cmd): 00041 space[re.findall('(^n\d+)out$',cmd)[0]] = command[cmd] 00042 elif re.match('^beg\d+$',cmd): 00043 dim = re.findall('^beg(\d+)$',cmd)[0] 00044 if command.has_key('end'+dim): 00045 space['n'+dim] = space['n'+dim] + command[cmd] + command['end'+dim] 00046 else: 00047 space['n'+dim] = space['n'+dim] + command[cmd] 00048 elif re.match('^end\d+$',cmd): 00049 dim = re.findall('^end(\d+)$',cmd)[0] 00050 if not command.has_key('beg'+dim): 00051 space['n'+dim] = space['n'+dim] + command[cmd] 00052 00053 """ 00054 We want to have: 00055 Back to original Size: 00056 """ 00057 def padAdjHelper(command,space,*spaces): 00058 for cmd in command.kparams.keys(): 00059 if re.match('^n\d+$',cmd): 00060 space[cmd] = command[cmd] 00061 elif re.match('^n\d+out$',cmd): 00062 space[re.findall('(^n\d+)out$',cmd)[0]] = command[cmd] 00063 elif re.match('^beg\d+$',cmd): 00064 dim = re.findall('^beg(\d+)$',cmd)[0] 00065 if command.has_key('end'+dim): 00066 space['n'+dim] = space['n'+dim] - command[cmd] - command['end'+dim] 00067 else: 00068 space['n'+dim] = space['n'+dim] - command[cmd] 00069 elif re.match('^end\d+$',cmd): 00070 dim = re.findall('^end(\d+)$',cmd)[0] 00071 if not command.has_key('beg'+dim): 00072 space['n'+dim] = space['n'+dim] - command[cmd] 00073 00074 """ 00075 And map the new paramters to f# and n#: 00076 beg1/end1: 00077 f1 = beg1 00078 Update n1 accordingly. 00079 n1 = n1(after pad) - end1 00080 n1/n1out: 00081 n1 = n1 00082 n1 = n1out 00083 """ 00084 00085 def shape(space): 00086 n_val = 1 00087 key = "n%(n_val)s" 00088 shp = [] 00089 while space.has_key(key): 00090 shp.append( space[key] ) 00091 00092 return shp 00093 00094 def padReplaceHelper(command,space): 00095 kparams = command.kparams 00096 00097 for par in kparams.keys(): 00098 if re.match('^n\d+$',par): 00099 pass 00100 elif re.match('^n\d+out$',par): 00101 kparams[re.findall('(^n\d+)out$',par)[0]] = kparams[par] 00102 kparams.pop(par) 00103 elif re.match('^beg\d+$',par): 00104 dim = re.findall('^beg(\d+)$',par)[0] 00105 if kparams.has_key('end'+dim): 00106 kparams['f'+dim] = kparams[par] 00107 kparams['n'+dim] = space['n'+dim] - kparams[par] - kparams['end'+dim] 00108 kparams.pop('end'+dim) 00109 kparams.pop(par) 00110 elif kparams.has_key(par): 00111 kparams['f'+dim] = kparams[par] 00112 kparams['n'+dim] = space['n'+dim] - kparams[par] 00113 kparams.pop(par) 00114 elif re.match('^end\d+$',par): 00115 dim = re.findall('^end(\d+)$',par)[0] 00116 if kparams.has_key('beg'+dim): 00117 kparams['n'+dim] = space['n'+dim] - kparams[par] - kparams['beg'+dim] 00118 kparams['f'+dim] = kparams['beg'+dim] 00119 kparams.pop('beg'+dim) 00120 kparams.pop(par) 00121 elif kparams.has_key(par): 00122 kparams['n'+dim] = space['n'+dim] - kparams[par] 00123 kparams.pop(par) 00124 return command 00125