Files
2019-09-23 16:57:54 +02:00

145 lines
2.8 KiB
C++

#pragma once
#include <string>
#include <boost/filesystem.hpp>
#include <Magick++.h>
#include <bitset> //in which we store our feature vectors
#include <algorithm> //for sorting
using namespace std;
using namespace Magick;
namespace fs = boost::filesystem;
//Virtual base class
//Holds definitions for all common functions of descriptors,
//but should be overloaded by a child class
class Mutation {
public:
virtual Image* getMutated(Image* img) = 0;
virtual string ToString() = 0;
virtual fs::path ToPath() {
return fs::path(this->ToString());
}
};
//Just the way dogs see
class Grayscale : public Mutation {
public:
Image* getMutated(Image* img) {
Image* mut = new Image(*img);
mut->type(GrayscaleType);
return mut;
}
string ToString() {
return "Grayscale";
}
};
//Mirrors over the vertical axis
class Flop : public Mutation {
public:
Image * getMutated(Image* img) {
Image* mut = new Image(*img);
mut->flop();
return mut;
}
string ToString() {
return "Flop";
}
};
//Very low quality JPEG re-encoding
class LowQ : public Mutation {
public:
Image * getMutated(Image* img) {
Image* mut = new Image(*img);
mut->quality(5);
return mut;
}
string ToString() {
return "Low Quality";
}
};
//Medium quality JPEG re-encoding
class JPEG : public Mutation {
public:
Image * getMutated(Image* img) {
Image* mut = new Image(*img);
mut->quality(45);
return mut;
}
string ToString() {
return "JPEG";
}
};
//A 50% hue-shift to the right
class Hue : public Mutation {
public:
Image * getMutated(Image* img) {
Image* mut = new Image(*img);
mut->modulate(100, 100, 150);
return mut;
}
string ToString() {
return "Hue";
}
};
//A 25% increase in brightness
class Brighten : public Mutation {
public:
Image * getMutated(Image* img) {
Image* mut = new Image(*img);
mut->modulate(125, 100, 100);
mut->sigmoidalContrast(false, 5.0);
return mut;
}
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() {
try {
watermark = new Image;
watermark->read("watermark.png");
} catch ( Magick::ErrorFileOpen &error ) {
watermark = new Image("40x40", "white");
}
}
Image * getMutated(Image* img) {
Image* mut = new Image(*img);
mut->composite(*watermark, "+10+10", OverCompositeOp);
return mut;
}
string ToString() {
return "Watermark";
}
private:
Image* watermark;
};