-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageSet.h
116 lines (88 loc) · 3.56 KB
/
ImageSet.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Luke Schlather
// Monday, June 14 2010
// Licensed under the GPLv3
#ifndef _IMAGELOADER_
#define _IMAGELOADER_
#include "CImg.h"
#include "Loom.h"
#include<vector>
#include<map>
#include<unistd.h>
typedef unsigned char uchar;
typedef cimg_library::CImg<uchar> Image;
typedef std::vector <std::vector <int> > Configuration;
/* class Node; */
/* class Node : public std::pair<int, std::vector<Node> > { */
/* }; */
typedef unsigned char uchar;
template <class T>
class CImgView {
public:
double topX,topY,width,height;
cimg_library::CImg<T>& base;
CImgView<T>(cimg_library::CImg<T>& bas, double x, double y);
CImgView<T>(cimg_library::CImg<T>& bas, double x, double y,double wid, double hei);
CImgView<T>(cimg_library::CImg<T>& bas);
T & operator()(double x, double y, double c) {
return base(topX+x,topY+y,c);
}
};
// Luke Schlather
// Tuesday, April 13 2010
// Licensed under the LGPL, see LICENSE.txt for the full text.
class ImageSet {
private:
static double width;
static double height;
cimg_library::CImgList<uchar> bunch;
uchar threshold;
protected:
ImageSet& copy(const ImageSet& src);
public:
// Reads all files in a directory, determines which ones are images,
// and scales them to width by height, adding them to the bunch CImgList.
// Error codes:
// 2: imagedir does not exist.
// 3: imagedir is not a directory.
ImageSet(const char* imagedir,bool recurse=0);
void readImagesFromDirectory(const char* imagedir,bool recurse=0);
ImageSet(const ImageSet& src);
ImageSet();
static ImageSet LoadSet(const char* setfile);
static ImageSet WriteSet(const char* setfile);
cimg_library::CImgList<uchar> & get_list() {return bunch;}
static void setWidth(const int& wid) { width = wid; }
static void setHeight(const int& hei) { height=hei; }
double getWidth() { return width; }
double getHeight() { return height; }
int count() { return bunch.width(); }
Image operator[] (const int & id);
ImageSet& operator= (const ImageSet src) { copy(src); return *this;}
// Takes a two-dimensional array of image ids, and outputs a single
// image built of those images. **Expects a rectangle.**
Image weave(std::vector< std::vector<int> >& matrix);
Image weaveAll(int x, int y);
Configuration unravel(cimg_library::CImg<uchar> & input);
std::map<int, std::vector<int> > similarityGraph;
// Sort based on a tolerance and percentage:
//Arguments:
//Threshold : maximum variation between color channels
// if you have 230 in a red value of img2 and 215 in red of img2,
// the variation would be 15. So it's abs(pixel1[c]-pixel2[c])
//pct : percentage of pixels that exceed the maximum
// tolerance.
// Return:
// A map holding groups of ids that fall within
// threshold and percentage bounds.
std::map<int, std::vector<int> > & sort(int thresh,double pct);
void setThreshold(uchar thresh) { threshold=thresh;}
std::vector< std::vector<int> > geneticAlgorithm(cimg_library::CImg<uchar> & mold, int iterations, int popcount, int thresh, double pct,int mutationRate=100);
std::vector< std::vector<int> > bruteForce (cimg_library::CImg<uchar> & mold, int thresh, double pct);
double percentMatch(int img1, int img2);
double percentMatch(CImgView<uchar> one, CImgView<uchar> two);
double percentMatch(cimg_library::CImg<uchar> &one, cimg_library::CImg<uchar> &two);
double percentMatch(cimg_library::CImg<uchar> &mold, double moldMinX, double moldMinY, cimg_library::CImg<uchar> &two);
int avgDistance(int img1, int img2);
int medDistance(int img1, int img2);
};
#endif // _IMAGELOADER_