mirror of
https://github.com/Relintai/pmlpp.git
synced 2024-11-08 13:12:09 +01:00
Added MLPPTransformsOld.
This commit is contained in:
parent
22cb7e7be4
commit
9c49101420
1
SCsub
1
SCsub
@ -79,6 +79,7 @@ sources = [
|
||||
"mlpp/regularization/reg_old.cpp",
|
||||
"mlpp/gauss_markov_checker/gauss_markov_checker_old.cpp",
|
||||
"mlpp/utilities/utilities_old.cpp",
|
||||
"mlpp/transforms/transforms_old.cpp",
|
||||
|
||||
"test/mlpp_tests.cpp",
|
||||
]
|
||||
|
56
mlpp/transforms/transforms_old.cpp
Normal file
56
mlpp/transforms/transforms_old.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
//
|
||||
// Transforms.cpp
|
||||
//
|
||||
// Created by Marc Melikyan on 11/13/20.
|
||||
//
|
||||
|
||||
#include "transforms_old.h"
|
||||
#include "../lin_alg/lin_alg.h"
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
// DCT ii.
|
||||
// https://www.mathworks.com/help/images/discrete-cosine-transform.html
|
||||
std::vector<std::vector<real_t>> MLPPTransformsOld::discreteCosineTransform(std::vector<std::vector<real_t>> A) {
|
||||
MLPPLinAlg alg;
|
||||
A = alg.scalarAdd(-128, A); // Center around 0.
|
||||
|
||||
std::vector<std::vector<real_t>> B;
|
||||
B.resize(A.size());
|
||||
for (uint32_t i = 0; i < B.size(); i++) {
|
||||
B[i].resize(A[i].size());
|
||||
}
|
||||
|
||||
int M = A.size();
|
||||
|
||||
for (uint32_t i = 0; i < B.size(); i++) {
|
||||
for (uint32_t j = 0; j < B[i].size(); j++) {
|
||||
real_t sum = 0;
|
||||
real_t alphaI;
|
||||
if (i == 0) {
|
||||
alphaI = 1 / std::sqrt(M);
|
||||
} else {
|
||||
alphaI = std::sqrt(real_t(2) / real_t(M));
|
||||
}
|
||||
real_t alphaJ;
|
||||
if (j == 0) {
|
||||
alphaJ = 1 / std::sqrt(M);
|
||||
} else {
|
||||
alphaJ = std::sqrt(real_t(2) / real_t(M));
|
||||
}
|
||||
|
||||
for (uint32_t k = 0; k < B.size(); k++) {
|
||||
for (uint32_t f = 0; f < B[k].size(); f++) {
|
||||
sum += A[k][f] * std::cos((M_PI * i * (2 * k + 1)) / (2 * M)) * std::cos((M_PI * j * (2 * f + 1)) / (2 * M));
|
||||
}
|
||||
}
|
||||
B[i][j] = sum;
|
||||
B[i][j] *= alphaI * alphaJ;
|
||||
}
|
||||
}
|
||||
return B;
|
||||
}
|
||||
|
||||
void MLPPTransformsOld::_bind_methods() {
|
||||
}
|
27
mlpp/transforms/transforms_old.h
Normal file
27
mlpp/transforms/transforms_old.h
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
#ifndef MLPP_TRANSFORMS_OLD_H
|
||||
#define MLPP_TRANSFORMS_OLD_H
|
||||
|
||||
//
|
||||
// Transforms.hpp
|
||||
//
|
||||
//
|
||||
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class MLPPTransformsOld : public Reference {
|
||||
GDCLASS(MLPPTransformsOld, Reference);
|
||||
|
||||
public:
|
||||
std::vector<std::vector<real_t>> discreteCosineTransform(std::vector<std::vector<real_t>> A);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
};
|
||||
|
||||
#endif /* Transforms_hpp */
|
Loading…
Reference in New Issue
Block a user