-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDCT.cpp
More file actions
35 lines (29 loc) · 1.03 KB
/
Copy pathDCT.cpp
File metadata and controls
35 lines (29 loc) · 1.03 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
//
// Created by Nicola Pierazzo on 02/08/16.
//
#include <fftw3.h>
#include "DCT.hpp"
namespace imgutils {
void dct_inplace(Image &img) {
int n[] = {img.rows(), img.columns()};
fftwf_r2r_kind dct2[] = {FFTW_REDFT10, FFTW_REDFT10};
fftwf_plan plan = fftwf_plan_many_r2r(2, n, img.channels(), img.data(), NULL,
1, img.pixels(), img.data(), NULL, 1,
img.pixels(), dct2, FFTW_ESTIMATE);
fftwf_execute(plan);
fftwf_destroy_plan(plan);
// Normalization
for (int i = 0; i < img.samples(); ++i) {
img.val(i) /= 4 * img.pixels();
}
}
void idct_inplace(Image &img) {
int n[] = {img.rows(), img.columns()};
fftwf_r2r_kind idct2[] = {FFTW_REDFT01, FFTW_REDFT01};
fftwf_plan plan = fftwf_plan_many_r2r(2, n, img.channels(), img.data(), NULL,
1, img.pixels(), img.data(), NULL, 1,
img.pixels(), idct2, FFTW_ESTIMATE);
fftwf_execute(plan);
fftwf_destroy_plan(plan);
}
}