34 #include <visp3/ustk_elastography/usConvolution2d.h>
36 #if defined(USTK_HAVE_FFTW)
43 : outa(NULL), outb(NULL), outc(NULL), out(NULL), ad(NULL), bd(NULL), p1(), p2(), p3(), m_init(false)
53 fftw_destroy_plan(p1);
54 fftw_destroy_plan(p2);
55 fftw_destroy_plan(p3);
74 if (Am != matrix1.getRows() || An != matrix1.getCols() || Bm != matrix2.getRows() || Bn != matrix2.getCols()) {
84 fftw_destroy_plan(p1);
85 fftw_destroy_plan(p2);
86 fftw_destroy_plan(p3);
89 Am = matrix1.getRows();
90 An = matrix1.getCols();
91 Bm = matrix2.getRows();
92 Bn = matrix2.getCols();
99 m_R.resize(h_dst, w_dst);
104 ad =
new fftw_complex[hf * wf];
105 bd =
new fftw_complex[hf * wf];
106 outa =
new fftw_complex[hf * wf];
107 outb =
new fftw_complex[hf * wf];
108 outc =
new fftw_complex[hf * wf];
109 out =
new fftw_complex[hf * wf];
112 p1 = fftw_plan_dft_2d(wf, hf, ad, outa, FFTW_FORWARD, FFTW_ESTIMATE);
113 p2 = fftw_plan_dft_2d(wf, hf, bd, outb, FFTW_FORWARD, FFTW_ESTIMATE);
114 p3 = fftw_plan_dft_2d(wf, hf, outc, out, FFTW_BACKWARD, FFTW_ESTIMATE);
132 init(matrix1, matrix2);
137 for (
unsigned int i = 0; i < wf * hf; ++i) {
138 outc[i][0] = (outa[i][0] * outb[i][0]) - (outa[i][1] * outb[i][1]);
139 outc[i][1] = (outa[i][0] * outb[i][1]) + (outa[i][1] * outb[i][0]);
143 int startX = vpMath::round((
double)(wf - w_dst) / 2.0);
144 int startY = vpMath::round((
double)(hf - h_dst) / 2.0);
145 int endX = startX + w_dst;
146 int endY = startY + h_dst;
149 for (
int i = startX; i < endX; ++i) {
151 for (
int j = startY; j < endY; ++j) {
153 m_R[l][k] = out[j + i * hf][0] / (double)(wf * hf);
162 void usConvolution2d::padding_zeros()
165 for (
unsigned int i = 0; i < wf; ++i) {
166 for (
unsigned int j = 0; j < hf; ++j) {
168 ad[j + i * hf][0] = ((j < Am) && (i < An)) ? m_M1[j][i] : 0.0;
169 ad[j + i * hf][1] = 0.0;
170 bd[j + i * hf][0] = ((j < Bm) && (i < Bn)) ? m_M2[j][i] : 0.0;
171 bd[j + i * hf][1] = 0.0;
vpMatrix run(const vpMatrix &matrix1, const vpMatrix &matrix2)
virtual ~usConvolution2d()
void init(const vpMatrix &matrix1, const vpMatrix &matrix2)