14 DWORD ftyp = GetFileAttributesA(dirName_in.c_str());
15 if (ftyp == INVALID_FILE_ATTRIBUTES)
18 if (ftyp & FILE_ATTRIBUTE_DIRECTORY)
26 WIN32_FIND_DATA FindFileData;
29 std::string dirName = dirName_in +
"*";
30 hFind = FindFirstFile(dirName.c_str(),&FindFileData);
31 if (hFind == INVALID_HANDLE_VALUE) {
32 printf (
"FindFirstFile failed (%d)\n", GetLastError());
36 while(FindNextFile(hFind,&FindFileData)){
44 WIN32_FIND_DATA FindFileData;
47 std::string dirName = dirName_in +
"*";
48 hFind = FindFirstFile(dirName.c_str(),&FindFileData);
49 if (hFind == INVALID_HANDLE_VALUE) {
50 printf (
"FindFirstFile failed (%d)\n", GetLastError());
54 while(FindNextFile(hFind,&FindFileData)){
55 std::string name = FindFileData.cFileName;
56 if(name.find(
".jpg")!=name.npos) {
72 std::cout << out << std::endl;
84 std::string file =
folder + filename +
".jpg";
93 std::string outfile =
folder + filename +
".txt";
94 while(fopen(outfile.c_str(),
"r")){
95 std::cout <<
"Output file " << filename <<
" already exists, please specify new filename:\n";
97 outfile =
folder + filename +
".txt";
101 std::cout <<
"Error creating output file "<< outfile <<
"\n\n";
102 std::cout <<
"Error " << outfile <<
" already exists, please specify new file path:\n";
118 printf_s(
"No output mode selected, using console by default.\n");
124 folder =
"D:\\TestImages\\TestOutput\\" + std::string(date) +
"\\";
125 if(!CreateDirectory((LPCTSTR)
folder.c_str(),NULL)){
126 printf_s(
"Error creating output folder");
136 if( x < 0 || y < 0 || x + w > img.
w || y + h > img.
h){
140 for(
int x_i = x; x_i < x+w; x_i++){
141 for(
int y_i = y; y_i < y+h; y_i++){
142 croppedImg.
at(x_i-x,y_i-y) = img.
at(x_i,y_i);
152 for(
int x_i=0;x_i<img.
w;x_i++){
153 for(
int y_i=0;y_i<img.
h;y_i++){
154 for(
int x_fact=0;x_fact<factor;x_fact++){
155 for(
int y_fact=0;y_fact<factor;y_fact++){
156 resizedImg.
at(x_i*factor+x_fact,y_i*factor+y_fact) = img.
at(x_i,y_i);
168 for(
int x_i=0;x_i<img1.
w;x_i++){
169 for(
int y_i=0;y_i<img2.
h;y_i++){
170 if(x_i-displacement.
x > 0 && x_i-displacement.
x < img1.
w && y_i-displacement.
y > 0 && y_i-displacement.
y < img1.
h) {
171 addedImg.
at(x_i,y_i) = ( img1.
at(x_i,y_i) + img2.
at(x_i-displacement.
x,y_i-displacement.
y) )/2;
173 addedImg.
at(x_i,y_i) = img1.
at(x_i,y_i);
184 for(
int x_i=0;x_i<img.
w;x_i++){
185 for(
int y_i=0;y_i<img.
h;y_i++){
186 float gaussfact = expf(- (x_i-centre.
x)*(x_i-centre.
x) / (2*sigma*sigma) - (y_i-centre.
y)*(y_i-centre.
y) / (2*sigma*sigma));
187 gaussImg.
at(x_i,y_i) = img.
at(x_i,y_i)*gaussfact;
200 float maxskew = median*stddev;
201 for(
int x_i=0;x_i<img.
w;x_i++){
202 for(
int y_i=0;y_i<img.
h;y_i++){
203 int diagonalOffset = (y_i - x_i*img.
h/img.
w);
204 float skew = fact*((float)diagonalOffset/img.
h)*maxskew;
205 skewImg.
at(x_i,y_i) = img.
at(x_i,y_i)+skew;
214 for(
int ii = 0; ii < size; ii++){
219 else if(ii < img.
w + img.
h - 1){
223 else if(ii < img.
w * 2 + img.
h - 2){
225 x = ii-(img.
h+img.
w-1);
229 y = ii-(img.
h+img.
w*2-3);
231 out[ii] = img.
at(x,y);
236 int size = img.
w * 2 + img.
h * 2 - 4;
237 float* outeredge =
new float[size];
239 std::sort(outeredge,outeredge+size);
242 median = (outeredge[(int)(size/2-1)] + outeredge[(int)(size/2+1)])/2;
244 median = outeredge[size/2];
250 int size = img.
w * 2 + img.
h * 2 - 4;
251 float* outeredge =
new float[size];
259 int size = img.
w * 2 + img.
h * 2 - 4;
260 float* outeredge =
new float[size];
263 for(
int ii = 0; ii < size; ii++){
264 sqsum += outeredge[ii]*outeredge[ii];
267 return sqrt(1/(
float)size*sqsum);
ImageData ResizeImage(ImageData img, int factor)
void GetFormattedTimeString(char *output)
float BackgroundRMS(ImageData img)
void GetOuterEdges(float *out, int size, ImageData img)
int NumJpgInDir(const std::string &dirName_in)
int NumFilesInDir(const std::string &dirName_in)
void outputImage(ImageData img, std::string filename="UsedImage")
void outputString(std::string out, bool ConsoleOnly=false)
ImageData AddImages(ImageData img1, ImageData img2, vector2f displacement)
float distance(vector2f a, vector2f b)
vector2< float > vector2f
vector3< T > sqrt(const vector3< T > &a)
static TImageData alloc(int w, int h)
T ComputeStdDev(T *data, int len)
ImageData CropImage(ImageData img, int x, int y, int w, int h)
float BackgroundMedian(ImageData img)
bool DirExists(const std::string &dirName_in)
void FloatToJPEGFile(const char *name, const float *d, int w, int h)
ImageData GaussMask(ImageData img, float sigma)
void newFile(std::string filename, const char *mode="a")
ImageData SkewImage(ImageData img, float fact)
float BackgroundStdDev(ImageData img)