[go: up one dir, main page]

Menu

[r353]: / trunk / cocolib / vtv / vtv.h  Maximize  Restore  History

Download this file

278 lines (205 with data), 9.8 kB

  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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#ifndef __COCO_VTV_H
#define __COCO_VTV_H
#include <map>
#include <vector>
#include <assert.h>
#include "../cuda/cuda_interface.h"
#include "../defs.h"
#include "../modules.h"
#include "../common/gsl_image.h"
namespace coco {
/*** CORE PDE METHODS ***/
struct coco_vtv_workspace;
struct coco_vtv_sr_data;
// Helper structure to set all parameters
struct coco_vtv_data
{
// Field size
size_t _W;
size_t _H;
size_t _N;
// Number of channels
size_t _nchannels;
// Smoothness parameter
double _lambda;
// Smoothness multiplicator for adaptive algorithms
double _lambda_max_factor;
// Step sizes (primal/dual)
double _tau;
double _sigma;
// Step sizes (fista)
double _alpha;
// Number of inner iterations (fista)
size_t _inner_iterations;
// Threshold to decide if pixels in interval
// (dips - _disp_threshold, dips + _disp_threshold) must be merged
double _disp_threshold;
// Lipschitz constant
double _L;
// Uniform convexity constant
double _gamma;
// Regularizer
// 0: TV_S
// 1: TV_F
// 2: TV_J
size_t _regularizer;
// Data term regularizer
// 1: L^1 - norm
// 2: L^2 - norm
// Works only together with Arrow-Hurwicz or Chambolle-Pock,
// and with general inverse problem
size_t _data_term_p;
// Super-resolution data (if initialized)
coco_vtv_sr_data *_sr_data;
// Base directory for test output
std::string _basedir;
// Number of bytes per image double layer
size_t _nfbytes;
// Workspace data
coco_vtv_workspace* _workspace;
};
// Alloc PDE data with sensible defaults
coco_vtv_data* coco_vtv_alloc( std::vector<gsl_matrix*> F );
// Free up PDE data
bool coco_vtv_free( coco_vtv_data *data );
// alloc rarely needed variables
bool coco_vtv_alloc_aux_fields( coco_vtv_data *data );
// Init local regularizer weights
bool coco_vtv_set_regularizer_weight( coco_vtv_data *data, gsl_matrix *g );
// Init local regularizer weights
bool coco_vtv_set_regularizer_weight( coco_vtv_data *data, std::vector<gsl_matrix*> g );
// Initialize workspace with current solution
bool coco_vtv_initialize( coco_vtv_data *data,
std::vector<gsl_matrix*> &U );
// Get current solution
bool coco_vtv_get_solution( coco_vtv_data *data,
std::vector<gsl_matrix*> &U );
// Get dual variable XI (vector of dimension 2)
bool coco_vtv_get_dual_xi( coco_vtv_data *data,
std::vector<gsl_matrix*> &XI,
size_t channel=0 );
// Get dual variable ETA (vector of dimension equal to channel number)
bool coco_vtv_get_dual_eta( coco_vtv_data *data,
std::vector<gsl_matrix*> &ETA );
/*****************************************************************************
TV_x ROF
*****************************************************************************/
// Compute primal energy
double coco_vtv_rof_primal_energy( coco_vtv_data *data );
// *** MTV-ROF base algorithms ***
// Perform one iteration of Bermudez-Morena scheme
bool coco_vtv_rof_iteration_bermudez_morena( coco_vtv_data *data );
// Perform one iteration of Arrow-Hurwicz scheme
bool coco_vtv_rof_iteration_arrow_hurwicz( coco_vtv_data *data );
// Perform one iteration of Algorithm 1, Chambolle-Pock
bool coco_vtv_rof_iteration_chambolle_pock_1( coco_vtv_data *data );
// Perform one iteration of Algorithm 2, Chambolle-Pock
bool coco_vtv_rof_iteration_chambolle_pock_2( coco_vtv_data *data );
// Perform one iteration of FISTA
bool coco_vtv_rof_iteration_fista( coco_vtv_data *data );
/*****************************************************************************
TV_x ROF-SUM
sum of ROF terms, each with point-wise weight scaled by 1/lambda
interface currently only supports 1D functions
*****************************************************************************/
// *** MTV-ROF base algorithms ***
// Init functional
bool coco_vtv_rof_sum_init( coco_vtv_data *data,
std::vector<gsl_matrix*> Fs,
std::vector<gsl_matrix*> weights );
// Perform one iteration of FISTA
bool coco_vtv_rof_sum_iteration_fista( coco_vtv_data *data );
/*****************************************************************************
TV_x Deblurring
*****************************************************************************/
// Init kernel
bool coco_vtv_set_separable_kernel( coco_vtv_data *data, gsl_vector *kernel_x, gsl_vector *kernel_y );
bool coco_vtv_set_kernel( coco_vtv_data *data, gsl_matrix *kernel );
// Compute primal energy
double coco_vtv_deblurring_primal_energy( coco_vtv_data *data );
// Perform one primal step (several iterations of gradient descent for the prox operator)
bool coco_vtv_deblurring_primal_step( coco_vtv_data *data );
// Perform one primal step (several iterations of gradient descent for the prox operator)
bool coco_vtv_deblurring_dual_step( coco_vtv_data *data );
// Single primal descent step (using functional gradient only)
bool coco_vtv_deblurring_primal_descent_step( coco_vtv_data *data );
// Perform one iteration of Algorithm 1, Chambolle-Pock
bool coco_vtv_deblurring_iteration_chambolle_pock_1( coco_vtv_data *data );
// Perform one iteration of Algorithm 2, Chambolle-Pock
bool coco_vtv_deblurring_iteration_chambolle_pock_2( coco_vtv_data *data );
// Perform one iteration of Arrow-Hurwicz
bool coco_vtv_deblurring_iteration_arrow_hurwicz( coco_vtv_data *data );
// Perform one single shrinkage step (ISTA)
bool coco_vtv_deblurring_ista_step( coco_vtv_data *data );
// Perform one full iteration of FISTA
bool coco_vtv_deblurring_iteration_fista( coco_vtv_data *data );
/*****************************************************************************
TV_x Zooming (essentially SR with a single image)
CURRENTLY USES SR IMPLEMENTATION, SO fx must be equal to fy
*****************************************************************************/
// Init functional
bool coco_vtv_zooming_init( coco_vtv_data *data, gsl_image *source );
// Perform one full iteration of FISTA
bool coco_vtv_zooming_iteration_fista( coco_vtv_data *data );
/*****************************************************************************
TV_x Superresolution
*****************************************************************************/
// Setup SR algorithm: init view and resolution data
bool coco_vtv_sr_init( coco_vtv_data *data, size_t nviews, size_t ds_factor );
// Free up data for SR algorithm
bool coco_vtv_sr_free( coco_vtv_data *data );
// set the ugrad threshold
void coco_vtv_sr_set_ugrad_threshold( coco_vtv_data *data, float ugrad_threshold);
// set the sigma value of the sensor noise
void coco_vtv_sr_set_sigma_sensor( coco_vtv_data *data, float sigma_sensor );
void coco_vtv_sr_set_sigma_disp( coco_vtv_data *data, float sigma_disp );
// Method used to remove last view : decreases nview in one element
// Used to "skip" the input view of the synthesised one
void coco_vtv_sr_remove_last_view( coco_vtv_data *data );
// End view creation, finalize data structures
bool coco_vtv_sr_end_view_creation( coco_vtv_data *data );
// Setup a single test view with globally constant displacement for testing.
// displacement is measured in percent of an original pixel.
// part 1: dmap and structure init
bool coco_vtv_sr_create_test_view( coco_vtv_data *data, size_t nview, double dx, double dy );
// part 2: image init (after "end_view_creation")
bool coco_vtv_sr_render_test_view( coco_vtv_data *data, size_t nview );
// Setup a single test view given a disparity map and source image
// displacement is measured in disparity map units
bool coco_vtv_sr_create_view( coco_vtv_data *data, size_t nview,
double dx, double dy,
gsl_image *view, float *disparity, float *disp_sigma = 0 );
// get view image, lores version
gsl_image *coco_vtv_sr_get_view_lores( coco_vtv_data *data, size_t nview );
// Compute new weights
bool coco_vtv_sr_compute_weights( coco_vtv_data *data );
// Compute interpolated image (just average of all inputs)
bool coco_vtv_sr_compute_averaged_forward_warp( coco_vtv_data *data );
// Initialize regularizer weight _g using sr->_target_mask
bool coco_vtv_sr_init_regularizer_weight( coco_vtv_data *data );
// Compute interpolated image from a single view
bool coco_vtv_sr_compute_forward_warp( coco_vtv_data *data, size_t nview );
// Compute primal energy
double coco_vtv_sr_primal_energy( coco_vtv_data *data );
// Perform one full iteration of FISTA
bool coco_vtv_sr_iteration_fista( coco_vtv_data *data );
// Perform one iteration of Algorithm 1, Chambolle-Pock
bool coco_vtv_sr_iteration_chambolle_pock_1( coco_vtv_data *data );
// Perform one iteration of Algorithm 1, Chambolle-Pock, experimental disparity optimization
bool coco_vtv_sr_dmap_iteration_chambolle_pock_1( coco_vtv_data *data );
// Experimental: optimize the disparity maps using the current solution, then
// re-initialize algorithm with new ones
bool vtv_sr_optimize_disparity_maps( coco_vtv_data *data );
/*****************************************************************************
TV_x Inpainting
*****************************************************************************/
// Init inpainting stencil
bool coco_vtv_set_stencil( coco_vtv_data *data, gsl_matrix *stencil );
// Compute primal energy
double coco_vtv_inpainting_primal_energy( coco_vtv_data *data );
// Perform one single shrinkage step (ISTA)
bool coco_vtv_inpainting_ista_step( coco_vtv_data *data );
// Perform one full iteration of FISTA
bool coco_vtv_inpainting_iteration_fista( coco_vtv_data *data );
}
#endif