1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : refocus deconvolution matrix implementation.
9
* Copyright (C) 2005-2007 by Gilles Caulier <caulier dot gilles at gmail dot com>
11
* This program is free software; you can redistribute it
12
* and/or modify it under the terms of the GNU General
13
* Public License as published by the Free Software Foundation;
14
* either version 2, or (at your option)
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* ============================================================ */
24
#ifndef MATRIX_H_INCLUDED
25
#define MATRIX_H_INCLUDED
31
namespace DigikamImagesPluginCore
36
* @radius: Radius of the matrix.
38
* Centered matrix. This is a square matrix where
39
* the indices range from [-radius, radius].
40
* The matrix contains (2 * radius + 1) ** 2 elements.
45
int radius; // Radius of the matrix
46
int row_stride; // Size of one row = 2 * radius + 1
47
double *data; // Contents of matrix
48
double *center; // Points to element with index (0, 0)
54
* @rows: Number of rows in the matrix.
56
* Normal matrix type. Indices range from
57
* [0, rows -1 ] and [0, cols - 1].
62
int rows; // Number of rows in the matrix
63
int cols; // Number of columns in the matrix
64
double *data; // Content of the matrix
73
static void fill_matrix (CMat * matrix, const int m, double f (int, int, double), const double fun_arg);
75
static void fill_matrix2 (CMat * matrix, const int m,
76
double f (const int, const int, const double, const double),
77
const double fun_arg1, const double fun_arg2);
79
static void make_circle_convolution (const double radius, CMat *convolution, const int m);
81
static void make_gaussian_convolution (const double alpha, CMat *convolution, const int m);
83
static void convolve_star_mat (CMat *result, const CMat *const mata, const CMat* const matb);
85
static CMat *compute_g_matrix (const CMat * const convolution, const int m,
86
const double gamma, const double noise_factor,
87
const double musq, const bool symmetric);
89
static void finish_matrix (Mat * mat);
90
static void finish_and_free_matrix (Mat * mat);
91
static void init_c_mat (CMat * mat, const int radius);
92
static void finish_c_mat (CMat * mat);
97
static void print_c_mat (const CMat * const mat);
98
static void print_matrix (Mat * matrix);
100
static Mat *allocate_matrix (int nrows, int ncols);
101
static double *mat_eltptr (Mat * mat, const int r, const int c);
102
static double mat_elt (const Mat * mat, const int r, const int c);
103
static CMat *allocate_c_mat (const int radius);
104
static inline double *c_mat_eltptr (CMat * mat, const int col, const int row);
105
static inline double c_mat_elt (const CMat * const mat, const int col, const int row);
106
static void convolve_mat (CMat * result, const CMat * const mata, const CMat * const matb);
107
static void convolve_mat_fun (CMat * result, const CMat * const mata, double (f) (int, int));
108
static int as_idx (const int k, const int l, const int m);
109
static int as_cidx (const int k, const int l);
110
static Mat *make_s_matrix (CMat * mat, int m, double noise_factor);
111
static Mat *make_s_cmatrix (CMat * mat, int m, double noise_factor);
112
static double correlation (const int x, const int y, const double gamma, const double musq);
113
static Mat *copy_vec (const CMat * const mat, const int m);
114
static Mat *copy_cvec (const CMat * const mat, const int m);
115
static CMat *copy_cvec2mat (const Mat * const cvec, const int m);
116
static CMat *copy_vec2mat (const Mat * const cvec, const int m);
117
static CMat *compute_g (const CMat * const convolution, const int m, const double gamma,
118
const double noise_factor, const double musq, const bool symmetric);
119
static double circle_integral (const double x, const double radius);
120
static double circle_intensity (const int x, const int y, const double radius);
122
// CLapack interface.
123
static int dgesv (const int N, const int NRHS, double *A, const int lda, double *B, const int ldb);
127
} // NameSpace DigikamImagesPluginCore
129
#endif /* MATRIX_H_INCLUDED */