Adds preview functions

This commit is contained in:
2019-03-12 00:43:10 +01:00
parent db665025bd
commit 8706e241a4
3 changed files with 33 additions and 5 deletions
+19 -4
View File
@@ -32,6 +32,12 @@ public:
return true; return true;
} }
//Function which should output some example(s) to file
//that show how this descriptor works.
virtual void preview(Image* img) {
cout << "No preview defined. :-( " << endl;
}
//Helper functions //Helper functions
//TODO: Move these somewhere else. Maybe a friend-class? //TODO: Move these somewhere else. Maybe a friend-class?
double* CalculateDCT(Image* img) { double* CalculateDCT(Image* img) {
@@ -125,7 +131,7 @@ public:
int green_b = (b << (64 - 16) >> (64 - 8)).to_ulong(); int green_b = (b << (64 - 16) >> (64 - 8)).to_ulong();
int blue_b = (b << (64 - 8) >> (64 - 8)).to_ulong(); int blue_b = (b << (64 - 8) >> (64 - 8)).to_ulong();
return abs(red_a - red_b) + abs(green_a - green_b) + abs(blue_a - blue_b); return abs(red_a - red_b) + abs(green_a - green_b) + abs(blue_a - blue_b);
}; }
string ToString() { string ToString() {
return "averageColor"; return "averageColor";
} }
@@ -332,7 +338,7 @@ public:
if (a[i] != b[i]) biterror++; if (a[i] != b[i]) biterror++;
} }
return biterror; return biterror;
}; }
string ToString() { string ToString() {
return "threshold"; return "threshold";
} }
@@ -365,10 +371,19 @@ public:
if (a[i] != b[i]) biterror++; if (a[i] != b[i]) biterror++;
} }
return biterror; return biterror;
}; }
string ToString() { string ToString() {
return "DCTPearson"; return "DCTPearson";
} }
void preview(Image* img){
Image* dct = new Image(*img);
Image* local_image = new Image(*img);
//double* converted = CalculateDCsT(dct);
local_image->type(GrayscaleType);
local_image->sample(Geometry("8x8!")); //64 pixels
local_image->write("DCTPearson.png");
}
}; };
class DCTMedian : public Descriptor { class DCTMedian : public Descriptor {
@@ -398,7 +413,7 @@ public:
if (a[i] != b[i]) biterror++; if (a[i] != b[i]) biterror++;
} }
return biterror; return biterror;
}; }
string ToString() { string ToString() {
return "DCTMedian"; return "DCTMedian";
} }
+10
View File
@@ -256,4 +256,14 @@ void DescriptorManager::outputRank(string imagename, int method) {
for (std::multiset<pair<unsigned long long, string>>::iterator it = distances.begin(); it != distances.end(); ++it) { for (std::multiset<pair<unsigned long long, string>>::iterator it = distances.begin(); it != distances.end(); ++it) {
cout << "(" << it->first << ", " << it->second << ")" << endl; cout << "(" << it->first << ", " << it->second << ")" << endl;
} }
}
//Just runs the preview functions of all the descriptors on given image.
//No need to init before this.
void DescriptorManager::generatePreviews(string imagename) {
fs::path imagePath(img_path / imagename);
Image* img = new Image(imagePath.generic_string());
for (int i = 0; i < numDescriptors; i++) {
descriptor_types[i]->preview(img);
}
} }
+4 -1
View File
@@ -20,7 +20,9 @@ using namespace Magick;
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
//Manager class for //Manager class for descriptors.
//Contains functions to load, store, process
//all images, descriptors and mutations
class DescriptorManager { class DescriptorManager {
public: public:
DescriptorManager(); DescriptorManager();
@@ -30,6 +32,7 @@ public:
void rankImages(string image_name, int method); void rankImages(string image_name, int method);
multiset<pair<unsigned long long, string>> rankMutations(string image_name, int method); multiset<pair<unsigned long long, string>> rankMutations(string image_name, int method);
void runExperiments(); void runExperiments();
void generatePreviews(string imagename);
void outputMap(int a); void outputMap(int a);
void outputMap(); void outputMap();
void outputRank(string imagename, int method); void outputRank(string imagename, int method);