-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquantification.cpp
More file actions
46 lines (35 loc) · 1.22 KB
/
quantification.cpp
File metadata and controls
46 lines (35 loc) · 1.22 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
36
37
38
39
40
41
42
43
#include <iostream>
#include <fstream>
#include <string>
#include <opencv/cv.hpp>
using namespace std;
using namespace cv;
Mat quantification(Mat m, int qualite){ // m : matrice d'entrée (résultat de la transf discrete , qualite : facteur de qualité (entre 0 et 25)
Mat sortie = Mat::zeros(8, 8, CV_32S);
//Matrice de quantification
Mat quantif = Mat::zeros(8, 8, CV_32F);
// Parcours sur la ligne
for(int r=0; r<8; r++) {
// Parcours sur la colonne
for(int c=0; c<8; c++) {
quantif.at<float>(r,c) = 1 + (r+c+1)*qualite; //Remplissage de la matrice de quantification
sortie.at<int>(r,c) = m.at<float>(r,c) / quantif.at<float>(r,c) ;
}
}
return sortie;
}
Mat dequantification(Mat m, int qualite){ // m : matrice quantifiée , qualite : le même facteur que pour la quantification
Mat sortie = Mat::zeros(8, 8, CV_32S);
//Matrice de quantification
Mat quantif = Mat::zeros(8, 8, CV_32S);
// Parcours sur la ligne
for(int r=0; r<8; r++) {
// Parcours sur la colonne
for(int c=0; c<8; c++) {
quantif.at<int>(r,c) = 1 + (r+c+1)*qualite; //Remplissage de la matrice de quantification
sortie.at<int>(r,c) = m.at<int>(r,c) * quantif.at<int>(r,c) ;
}
}
sortie.convertTo(sortie, CV_64FC1);
return sortie;
}