digiKam
refocusmatrix.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2005-04-29
7  * Description : refocus deconvolution matrix implementation.
8  *
9  * Copyright (C) 2005-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  *
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)
15  * any later version.
16  *
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.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_REFOCUS_MATRIX_H
25 #define DIGIKAM_REFOCUS_MATRIX_H
26 
27 // C ++ includes
28 
29 #ifndef Q_CC_MSVC
30 # include <cstdio>
31 #endif
32 
33 namespace Digikam
34 {
35 
44 typedef struct
45 {
49  int radius;
57  double* data;
61  double* center;
62 }
63 CMat;
64 
65 // ---------------------------------------------------------------------------------------------
66 
74 typedef struct
75 {
79  int rows;
83  int cols;
87  double* data;
88 }
89 Mat;
90 
91 // ---------------------------------------------------------------------------------------------
92 
94 {
95 
96 public:
97 
98  static void fill_matrix(CMat* const matrix, const int m, double f(const int, const int, const double), const double fun_arg);
99 
100  static void fill_matrix2(CMat* const matrix, const int m,
101  double f(const int, const int, const double, const double),
102  const double fun_arg1, const double fun_arg2);
103 
104  static void make_circle_convolution(const double radius, CMat* const convolution, const int m);
105 
106  static void make_gaussian_convolution(const double alpha, CMat* const convolution, const int m);
107 
108  static void convolve_star_mat(CMat* const result, const CMat* const mata, const CMat* const matb);
109 
110  static CMat* compute_g_matrix(const CMat* const convolution, const int m,
111  const double gamma, const double noise_factor,
112  const double musq, const bool symmetric);
113 
114  static void finish_matrix(Mat* const mat);
115  static void finish_and_free_matrix(Mat* const mat);
116  static void init_c_mat(CMat* const mat, const int radius);
117  static void finish_c_mat(CMat* const mat);
118 
119  static double mat_elt(const Mat* const mat, const int r, const int c);
120  static inline double c_mat_elt(const CMat* const mat, const int col, const int row);
121 
122 private:
123 
124  static Mat* allocate_matrix(int nrows, int ncols);
125  static CMat* allocate_c_mat(const int radius);
126 
127  static double* mat_eltptr(Mat* const mat, const int r, const int c);
128 
129  static inline double* c_mat_eltptr(CMat* const mat, const int col, const int row);
130 
131  static void convolve_mat(CMat* const result, const CMat* const mata, const CMat* const matb);
132 
133  static int as_idx(const int k, const int l, const int m);
134  static int as_cidx(const int k, const int l);
135 
136  static Mat* make_s_matrix(CMat* const mat, int m, double noise_factor);
137  static Mat* make_s_cmatrix(CMat* const mat, int m, double noise_factor);
138 
139  static double correlation(const int x, const int y, const double gamma, const double musq);
140 
141  static Mat* copy_vec(const CMat* const mat, const int m);
142  static Mat* copy_cvec(const CMat* const mat, const int m);
143  static CMat* copy_cvec2mat(const Mat* const cvec, const int m);
144  static CMat* copy_vec2mat(const Mat* const cvec, const int m);
145  static CMat* compute_g(const CMat* const convolution, const int m, const double gamma,
146  const double noise_factor, const double musq, const bool symmetric);
147 
148  static double circle_integral(const double x, const double radius);
149  static double circle_intensity(const int x, const int y, const double radius);
150 };
151 
152 } // namespace Digikam
153 
154 #endif // DIGIKAM_REFOCUS_MATRIX_H
Definition: refocusmatrix.h:94
static void init_c_mat(CMat *const mat, const int radius)
Definition: refocusmatrix.cpp:147
static void convolve_star_mat(CMat *const result, const CMat *const mata, const CMat *const matb)
Definition: refocusmatrix.cpp:213
static void fill_matrix(CMat *const matrix, const int m, double f(const int, const int, const double), const double fun_arg)
Definition: refocusmatrix.cpp:497
static double c_mat_elt(const CMat *const mat, const int col, const int row)
Definition: refocusmatrix.cpp:178
static void finish_c_mat(CMat *const mat)
Definition: refocusmatrix.cpp:165
static CMat * compute_g_matrix(const CMat *const convolution, const int m, const double gamma, const double noise_factor, const double musq, const bool symmetric)
Definition: refocusmatrix.cpp:462
static void make_circle_convolution(const double radius, CMat *const convolution, const int m)
Definition: refocusmatrix.cpp:661
static void fill_matrix2(CMat *const matrix, const int m, double f(const int, const int, const double, const double), const double fun_arg1, const double fun_arg2)
Definition: refocusmatrix.cpp:513
static void finish_and_free_matrix(Mat *const mat)
Definition: refocusmatrix.cpp:125
static void make_gaussian_convolution(const double alpha, CMat *const convolution, const int m)
Definition: refocusmatrix.cpp:529
static void finish_matrix(Mat *const mat)
Definition: refocusmatrix.cpp:120
static double mat_elt(const Mat *const mat, const int r, const int c)
Definition: refocusmatrix.cpp:139
MetaEngineRotation matrix(MetaEngineRotation::TransformationAction action)
Definition: metaengine_rotation.cpp:81
Definition: datefolderview.cpp:43
Definition: refocusmatrix.h:45
int radius
Definition: refocusmatrix.h:49
int row_stride
Definition: refocusmatrix.h:53
double * data
Definition: refocusmatrix.h:57
double * center
Definition: refocusmatrix.h:61
Definition: refocusmatrix.h:75
int cols
Definition: refocusmatrix.h:83
int rows
Definition: refocusmatrix.h:79
double * data
Definition: refocusmatrix.h:87