diff --git a/Descriptor.h b/Descriptor.h index ccf473f..db33ab0 100644 --- a/Descriptor.h +++ b/Descriptor.h @@ -32,6 +32,12 @@ public: 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 //TODO: Move these somewhere else. Maybe a friend-class? double* CalculateDCT(Image* img) { @@ -125,7 +131,7 @@ public: int green_b = (b << (64 - 16) >> (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); - }; + } string ToString() { return "averageColor"; } @@ -332,7 +338,7 @@ public: if (a[i] != b[i]) biterror++; } return biterror; - }; + } string ToString() { return "threshold"; } @@ -365,10 +371,19 @@ public: if (a[i] != b[i]) biterror++; } return biterror; - }; + } string ToString() { 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 { @@ -398,7 +413,7 @@ public: if (a[i] != b[i]) biterror++; } return biterror; - }; + } string ToString() { return "DCTMedian"; } diff --git a/DescriptorManager.cpp b/DescriptorManager.cpp index 5bf0eaa..d86d156 100644 --- a/DescriptorManager.cpp +++ b/DescriptorManager.cpp @@ -256,4 +256,14 @@ void DescriptorManager::outputRank(string imagename, int method) { for (std::multiset>::iterator it = distances.begin(); it != distances.end(); ++it) { 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); + } } \ No newline at end of file diff --git a/DescriptorManager.h b/DescriptorManager.h index 3ba9db2..7f876ac 100644 --- a/DescriptorManager.h +++ b/DescriptorManager.h @@ -20,7 +20,9 @@ using namespace Magick; namespace fs = boost::filesystem; -//Manager class for +//Manager class for descriptors. +//Contains functions to load, store, process +//all images, descriptors and mutations class DescriptorManager { public: DescriptorManager(); @@ -30,6 +32,7 @@ public: void rankImages(string image_name, int method); multiset> rankMutations(string image_name, int method); void runExperiments(); + void generatePreviews(string imagename); void outputMap(int a); void outputMap(); void outputRank(string imagename, int method);