Adds DCTMedian
Probably DCT Average would work better..
This commit is contained in:
@@ -360,4 +360,35 @@ public:
|
|||||||
string ToString() {
|
string ToString() {
|
||||||
return "Discrete Cosine Transform - Pearson Code";
|
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";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
@@ -10,6 +10,7 @@ DescriptorManager::DescriptorManager(const fs::path & image_path) {
|
|||||||
img_path = image_path;
|
img_path = image_path;
|
||||||
|
|
||||||
//Manual definitions.. SAD!
|
//Manual definitions.. SAD!
|
||||||
|
descriptor_types[7] = new DCTMedian();
|
||||||
descriptor_types[6] = new DCTPearson();
|
descriptor_types[6] = new DCTPearson();
|
||||||
descriptor_types[5] = new threshold();
|
descriptor_types[5] = new threshold();
|
||||||
descriptor_types[4] = new pearson();
|
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
|
//can be called directly or is called by its overload
|
||||||
//assumes a < numDescriptors
|
//assumes a < numDescriptors
|
||||||
void DescriptorManager::outputMap(int a) {
|
void DescriptorManager::outputMap(int a) {
|
||||||
if (a != 6) return;
|
if (a != 7) return;
|
||||||
cout << "Outputting map " << descriptor_types[a]->ToString() << endl;
|
cout << "Outputting map " << descriptor_types[a]->ToString() << endl;
|
||||||
map<string, bitset<64>> a_map = descriptors[a];
|
map<string, bitset<64>> a_map = descriptors[a];
|
||||||
if (a_map.begin() == a_map.end()) {
|
if (a_map.begin() == a_map.end()) {
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ public:
|
|||||||
void outputMap(int a);
|
void outputMap(int a);
|
||||||
void outputMap();
|
void outputMap();
|
||||||
private:
|
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
|
map<string, bitset<64>> descriptors[numDescriptors]; //array of maps that will hold the descriptors
|
||||||
fs::path img_path; //where the images are
|
fs::path img_path; //where the images are
|
||||||
Descriptor* descriptor_types[numDescriptors];
|
Descriptor* descriptor_types[numDescriptors];
|
||||||
|
|||||||
Reference in New Issue
Block a user