summaryrefslogtreecommitdiffstats
path: root/src/Python/ccpi/filters/regularisers.py
blob: bc745fe8b55b2f395e43c79c1f13cd72cf98c081 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
"""
script which assigns a proper device core function based on a flag ('cpu' or 'gpu')
"""

from ccpi.filters.cpu_regularisers import TV_ROF_CPU, TV_FGP_CPU, TV_PD_CPU, TV_SB_CPU, dTV_FGP_CPU, TNV_CPU, NDF_CPU, Diff4th_CPU, TGV_CPU, LLT_ROF_CPU, PATCHSEL_CPU, NLTV_CPU
try:
    from ccpi.filters.gpu_regularisers import TV_ROF_GPU, TV_FGP_GPU, TV_SB_GPU, dTV_FGP_GPU, NDF_GPU, Diff4th_GPU, TGV_GPU, LLT_ROF_GPU, PATCHSEL_GPU
    gpu_enabled = True
except ImportError:
    gpu_enabled = False
from ccpi.filters.cpu_regularisers import NDF_INPAINT_CPU, NVM_INPAINT_CPU

def ROF_TV(inputData, regularisation_parameter, iterations,
                     time_marching_parameter,tolerance_param,device='cpu'):
    if device == 'cpu':
        return TV_ROF_CPU(inputData,
                     regularisation_parameter,
                     iterations,
                     time_marching_parameter,
                     tolerance_param)
    elif device == 'gpu' and gpu_enabled:
        return TV_ROF_GPU(inputData,
                     regularisation_parameter,
                     iterations,
                     time_marching_parameter,
                     tolerance_param)
    else:
        if not gpu_enabled and device == 'gpu':
            raise ValueError ('GPU is not available')
        raise ValueError('Unknown device {0}. Expecting gpu or cpu'\
                         .format(device))

def FGP_TV(inputData, regularisation_parameter,iterations,
                     tolerance_param, methodTV, nonneg, device='cpu'):
    if device == 'cpu':
        return TV_FGP_CPU(inputData,
                     regularisation_parameter,
                     iterations,
                     tolerance_param,
                     methodTV,
                     nonneg)
    elif device == 'gpu' and gpu_enabled:
        return TV_FGP_GPU(inputData,
                     regularisation_parameter,
                     iterations,
                     tolerance_param,
                     methodTV,
                     nonneg)
    else:
        if not gpu_enabled and device == 'gpu':
            raise ValueError ('GPU is not available')
        raise ValueError('Unknown device {0}. Expecting gpu or cpu'\
                         .format(device))

def PD_TV(inputData, regularisation_parameter, iterations,
                     tolerance_param, methodTV, nonneg, lipschitz_const, tau, device='cpu'):
    if device == 'cpu':
        return TV_PD_CPU(inputData,
                     regularisation_parameter,
                     iterations,
                     tolerance_param,
                     methodTV,
                     nonneg,
                     lipschitz_const,
                     tau)
    elif device == 'gpu' and gpu_enabled:
        return TV_PD_CPU(inputData,
                     regularisation_parameter,
                     iterations,
                     tolerance_param,
                     methodTV,
                     nonneg,
                     lipschitz_const,
                     tau)
    else:
        if not gpu_enabled and device == 'gpu':
            raise ValueError ('GPU is not available')
        raise ValueError('Unknown device {0}. Expecting gpu or cpu'\
                         .format(device))

def SB_TV(inputData, regularisation_parameter, iterations,
                     tolerance_param, methodTV, device='cpu'):
    if device == 'cpu':
        return TV_SB_CPU(inputData,
                     regularisation_parameter,
                     iterations,
                     tolerance_param,
                     methodTV)
    elif device == 'gpu' and gpu_enabled:
        return TV_SB_GPU(inputData,
                     regularisation_parameter,
                     iterations,
                     tolerance_param,
                     methodTV)
    else:
        if not gpu_enabled and device == 'gpu':
            raise ValueError ('GPU is not available')
        raise ValueError('Unknown device {0}. Expecting gpu or cpu'\
                         .format(device))
def LLT_ROF(inputData, regularisation_parameterROF, regularisation_parameterLLT, iterations,
                     time_marching_parameter, tolerance_param, device='cpu'):
    if device == 'cpu':
        return LLT_ROF_CPU(inputData, regularisation_parameterROF, regularisation_parameterLLT, iterations, time_marching_parameter, tolerance_param)
    elif device == 'gpu' and gpu_enabled:
        return LLT_ROF_GPU(inputData, regularisation_parameterROF, regularisation_parameterLLT, iterations, time_marching_parameter, tolerance_param)
    else:
        if not gpu_enabled and device == 'gpu':
            raise ValueError ('GPU is not available')
        raise ValueError('Unknown device {0}. Expecting gpu or cpu'\
                         .format(device))
def TGV(inputData, regularisation_parameter, alpha1, alpha0, iterations,
                     LipshitzConst, tolerance_param, device='cpu'):
    if device == 'cpu':
        return TGV_CPU(inputData,
					regularisation_parameter,
					alpha1,
					alpha0,
					iterations,
                    LipshitzConst,
                    tolerance_param)
    elif device == 'gpu' and gpu_enabled:
        return TGV_GPU(inputData,
					regularisation_parameter,
					alpha1,
					alpha0,
					iterations,
                    LipshitzConst,
                    tolerance_param)
    else:
        if not gpu_enabled and device == 'gpu':
            raise ValueError ('GPU is not available')
        raise ValueError('Unknown device {0}. Expecting gpu or cpu'\
                         .format(device))
def NDF(inputData, regularisation_parameter, edge_parameter, iterations,
                     time_marching_parameter, penalty_type, tolerance_param, device='cpu'):
    if device == 'cpu':
        return NDF_CPU(inputData,
                     regularisation_parameter,
                     edge_parameter,
                     iterations,
                     time_marching_parameter,
                     penalty_type,
                     tolerance_param)
    elif device == 'gpu' and gpu_enabled:
        return NDF_GPU(inputData,
                     regularisation_parameter,
                     edge_parameter,
                     iterations,
                     time_marching_parameter,
                     penalty_type,
                     tolerance_param)
    else:
        if not gpu_enabled and device == 'gpu':
    	    raise ValueError ('GPU is not available')
        raise ValueError('Unknown device {0}. Expecting gpu or cpu'\
                         .format(device))
def Diff4th(inputData, regularisation_parameter, edge_parameter, iterations,
                     time_marching_parameter, tolerance_param, device='cpu'):
    if device == 'cpu':
        return Diff4th_CPU(inputData,
                     regularisation_parameter,
                     edge_parameter,
                     iterations,
                     time_marching_parameter,
                     tolerance_param)
    elif device == 'gpu' and gpu_enabled:
        return Diff4th_GPU(inputData,
                     regularisation_parameter,
                     edge_parameter,
                     iterations,
                     time_marching_parameter,
                     tolerance_param)
    else:
        if not gpu_enabled and device == 'gpu':
            raise ValueError ('GPU is not available')
        raise ValueError('Unknown device {0}. Expecting gpu or cpu'\
                         .format(device))
def FGP_dTV(inputData, refdata, regularisation_parameter, iterations,
                     tolerance_param, eta_const, methodTV, nonneg, device='cpu'):
    if device == 'cpu':
        return dTV_FGP_CPU(inputData,
                     refdata,
                     regularisation_parameter,
                     iterations,
                     tolerance_param,
                     eta_const,
                     methodTV,
                     nonneg)
    elif device == 'gpu' and gpu_enabled:
        return dTV_FGP_GPU(inputData,
                     refdata,
                     regularisation_parameter,
                     iterations,
                     tolerance_param,
                     eta_const,
                     methodTV,
                     nonneg)
    else:
        if not gpu_enabled and device == 'gpu':
            raise ValueError ('GPU is not available')
        raise ValueError('Unknown device {0}. Expecting gpu or cpu'\
                         .format(device))
def TNV(inputData, regularisation_parameter, iterations, tolerance_param):
        return TNV_CPU(inputData,
                     regularisation_parameter,
                     iterations,
                     tolerance_param)
def PatchSelect(inputData, searchwindow, patchwindow, neighbours, edge_parameter, device='cpu'):
    if device == 'cpu':
        return PATCHSEL_CPU(inputData,
                     searchwindow,
                     patchwindow,
                     neighbours,
                     edge_parameter)
    elif device == 'gpu' and gpu_enabled:
        return PATCHSEL_GPU(inputData,
                     searchwindow,
                     patchwindow,
                     neighbours,
                     edge_parameter)
    else:
        if not gpu_enabled and device == 'gpu':
            raise ValueError ('GPU is not available')
        raise ValueError('Unknown device {0}. Expecting gpu or cpu'\
                         .format(device))

def NLTV(inputData, H_i, H_j, H_k, Weights, regularisation_parameter, iterations):
    return NLTV_CPU(inputData,
                     H_i,
                     H_j,
                     H_k,
                     Weights,
                     regularisation_parameter,
                     iterations)
def NDF_INP(inputData, maskData, regularisation_parameter, edge_parameter, iterations,
                     time_marching_parameter, penalty_type):
        return NDF_INPAINT_CPU(inputData, maskData, regularisation_parameter,
        edge_parameter, iterations, time_marching_parameter, penalty_type)

def NVM_INP(inputData, maskData, SW_increment, iterations):
        return NVM_INPAINT_CPU(inputData, maskData, SW_increment, iterations)