Adds DCTMedian

Probably DCT Average would work better..
This commit is contained in:
Mark Hoekveen
2018-06-30 15:36:07 +02:00
parent dba94c125e
commit 8b4035eed1
3 changed files with 34 additions and 2 deletions
+31
View File
@@ -361,3 +361,34 @@ public:
return "Discrete Cosine Transform - Pearson Code";
}
};
class DCTMedian : public Descriptor {
public:
bitset<64> feature(Image* img) {
double* converted = CalculateDCT(img);
double bullshit[64];
for (ssize_t i = 0; i < 64; i++) {
bullshit[i] = converted[i];
}
sort(bullshit, bullshit + 64);
float median = (float)(bullshit[31] + bullshit[32]) / 2;
bitset<64> retval(0);
for (ssize_t i = 0; i < 64; i++) {
retval <<= 1;
if (converted[i] > median)
retval |= bitset<64>(1);
}
return retval;
}
unsigned long long distance(bitset<64> a, bitset<64> b) {
int biterror = 0;
for (int i = 0; i < 64; i++) {
if (a[i] != b[i]) biterror++;
}
return biterror;
};
string ToString() {
return "Discrete Cosine Transform - Median Code";
}
};
+2 -1
View File
@@ -10,6 +10,7 @@ DescriptorManager::DescriptorManager(const fs::path & image_path) {
img_path = image_path;
//Manual definitions.. SAD!
descriptor_types[7] = new DCTMedian();
descriptor_types[6] = new DCTPearson();
descriptor_types[5] = new threshold();
descriptor_types[4] = new pearson();
@@ -122,7 +123,7 @@ void DescriptorManager::similarImages(string image_name, int method, int numImag
//can be called directly or is called by its overload
//assumes a < numDescriptors
void DescriptorManager::outputMap(int a) {
if (a != 6) return;
if (a != 7) return;
cout << "Outputting map " << descriptor_types[a]->ToString() << endl;
map<string, bitset<64>> a_map = descriptors[a];
if (a_map.begin() == a_map.end()) {
+1 -1
View File
@@ -30,7 +30,7 @@ public:
void outputMap(int a);
void outputMap();
private:
static const int numDescriptors = 7; //TODO: automagically update this?
static const int numDescriptors = 8; //TODO: automagically update this?
map<string, bitset<64>> descriptors[numDescriptors]; //array of maps that will hold the descriptors
fs::path img_path; //where the images are
Descriptor* descriptor_types[numDescriptors];