From f2466a63ec9c097f94f0e5620db72e741e498bee Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Wed, 6 Mar 2019 20:07:00 +0100 Subject: [PATCH] Adds Crop and Watermark mutations --- DescriptorManager.cpp | 3 ++- DescriptorManager.h | 2 +- Mutation.h | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/DescriptorManager.cpp b/DescriptorManager.cpp index fe4cd21..5bf0eaa 100644 --- a/DescriptorManager.cpp +++ b/DescriptorManager.cpp @@ -20,12 +20,13 @@ DescriptorManager::DescriptorManager(const fs::path & image_path) { descriptor_types[0] = new averageColor(); mutators[0] = new Grayscale(); - mutators[1] = new Flip(); + mutators[1] = new Crop(); mutators[2] = new Flop(); mutators[3] = new JPEG(); mutators[4] = new LowQ(); mutators[5] = new Hue(); mutators[6] = new Brighten(); + mutators[7] = new Watermark(); } //No need to call destructor.. yet? diff --git a/DescriptorManager.h b/DescriptorManager.h index b8056e8..3ba9db2 100644 --- a/DescriptorManager.h +++ b/DescriptorManager.h @@ -35,7 +35,7 @@ public: void outputRank(string imagename, int method); private: static const int numDescriptors = 8; - static const int numMutations = 7; + static const int numMutations = 8; //TODO: automagically update this? bool initialized = false; diff --git a/Mutation.h b/Mutation.h index b062aa2..7040469 100644 --- a/Mutation.h +++ b/Mutation.h @@ -101,4 +101,41 @@ public: string ToString() { return "Brighten"; } +}; + +//shaves off some pixels from the bottomright edge of the image +class Crop : public Mutation { +public: + Image * getMutated(Image* img) { + Image* mut = new Image(*img); + ssize_t n = mut->rows(); + ssize_t m = mut->columns(); + float shave = 0.1; + n *= 1.0 - shave; + m *= 1.0 - shave; + mut->crop(Geometry(m, n, 0, 0)); + return mut; + } + string ToString() { + return "Crop"; + } +}; + +//Adds a logo to the top-left corner of the image +class Watermark : public Mutation { +public: + Watermark() { + watermark = new Image; + watermark->read("watermark.png"); + } + Image * getMutated(Image* img) { + Image* mut = new Image(*img); + mut->composite(*watermark, "+10+10", OverCompositeOp); + return mut; + } + string ToString() { + return "Watermark"; + } +private: + Image* watermark; }; \ No newline at end of file