18 #ifndef PIC_ALGORITHMS_DISCRETE_COSINE_TRANSFORM_HPP 19 #define PIC_ALGORITHMS_DISCRETE_COSINE_TRANSFORM_HPP 21 #include "../image.hpp" 22 #include "../util/tile_list.hpp" 62 float size2 = float(size * 2);
63 float squareRoot2 = sqrtf(2.0f);
64 float squareRoot = sqrtf(2.0f /
float(size));
65 float squareRootPow2 = squareRoot * squareRoot;
71 for(
unsigned int t = 0; t < tiles.
tiles.size(); t++) {
74 for(
int v = box.
y0; v < box.
y1; v++) {
77 for(
int u = box.
x0; u < box.
x1; u++) {
80 float *dataOut = (*imgOut)(u, v);
82 for(
int p = 0; p < channels; p++) {
86 for(
int y = 0; y < size; y++) {
88 int val = vr * (2 * y + 1);
89 float cosU = cosf(
C_PI *
float(val) / size2);
91 for(
int x = 0; x < size; x++) {
93 val = ur * (2 * x + 1);
94 float tot = cosU * cosf(
C_PI *
float(val) / size2);
96 float *dataIn = (*imgIn)(xi, yi);
98 for(
int p = 0; p < channels; p++) {
99 dataOut[p] += tot * dataIn[p];
105 for(
int p = 0; p < channels; p++) {
106 dataOut[p] /= squareRoot2;
111 for(
int p = 0; p < channels; p++) {
112 dataOut[p] /= squareRoot2;
116 for(
int p = 0; p < channels; p++) {
117 dataOut[p] *= squareRootPow2;
147 float size2 = float(size * 2);
148 float squareRoot2 = sqrtf(2.0f);
149 float squareRoot = sqrtf(2.0f /
float(size));
150 float squareRootPow2 = squareRoot * squareRoot;
156 for(
unsigned int t = 0; t < tiles.
tiles.size(); t++) {
159 for(
int y = box.
y0; y < box.
y1; y++) {
162 for(
int x = box.
x0; x < box.
x1; x++) {
165 float *dataOut = (*imgOut)(x, y);
167 for(
int p = 0; p < channels; p++) {
171 for(
int v = 0; v < size; v++) {
173 int val = v * (2 * yr + 1);
174 float cosU = cosf(
C_PI *
float(val) / size2);
180 for(
int u = 0; u < size; u++) {
182 val = u * (2 * xr + 1);
183 float tot = cosU * cosf(
C_PI *
float(val) / size2);
189 float *dataIn = (*imgIn)(ui, vi);
191 for(
int p = 0; p < channels; p++) {
192 dataOut[p] += tot * dataIn[p];
197 for(
int p = 0; p < channels; p++) {
198 dataOut[p] *= squareRootPow2;
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
int channels
Definition: image.hpp:80
int x0
Definition: bbox.hpp:32
BBox getBBox(int index)
genBBox
const float C_PI
Definition: math.hpp:50
The DCT class provides a reference implementation for Discret Cosine Transform.
Definition: discrete_cosine_transform.hpp:30
static Image * inverse(Image *imgIn, Image *imgOut, int size=8)
inverse computes the inverse DCT transformation.
Definition: discrete_cosine_transform.hpp:133
int y0
Definition: bbox.hpp:32
The TileList class.
Definition: tile_list.hpp:33
static Image * transform(Image *imgIn, Image *imgOut, int size=8)
transform computes the forward DCT transformation.
Definition: discrete_cosine_transform.hpp:48
DCT()
DCT.
Definition: discrete_cosine_transform.hpp:37
int x1
Definition: bbox.hpp:32
The Image class stores an image as buffer of float.
Definition: image.hpp:60
int y1
Definition: bbox.hpp:32
Image * allocateSimilarOne()
allocateSimilarOne creates an Image with similar size of the calling instance.
Definition: bilateral_separation.hpp:25
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80
std::vector< Tile > tiles
tiles a list of tiles
Definition: tile_list.hpp:50