diff --git a/Descriptor.h b/Descriptor.h index 5dd8cb2..39f4697 100644 --- a/Descriptor.h +++ b/Descriptor.h @@ -360,4 +360,35 @@ public: string ToString() { 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"; + } }; \ No newline at end of file diff --git a/DescriptorManager.cpp b/DescriptorManager.cpp index 6c7cec8..add05d6 100644 --- a/DescriptorManager.cpp +++ b/DescriptorManager.cpp @@ -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> a_map = descriptors[a]; if (a_map.begin() == a_map.end()) { diff --git a/DescriptorManager.h b/DescriptorManager.h index cc6b842..3bd80df 100644 --- a/DescriptorManager.h +++ b/DescriptorManager.h @@ -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> descriptors[numDescriptors]; //array of maps that will hold the descriptors fs::path img_path; //where the images are Descriptor* descriptor_types[numDescriptors];