Adds Crop and Watermark mutations

This commit is contained in:
Mark Hoekveen
2019-03-06 20:07:00 +01:00
parent 3ffb39ea73
commit f2466a63ec
3 changed files with 40 additions and 2 deletions
+2 -1
View File
@@ -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?
+1 -1
View File
@@ -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;
+37
View File
@@ -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;
};