#include <time.h>
#include <string>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include "testutils.h"
Go to the source code of this file.
|
float | distance (vector2f a, vector2f b) |
|
bool | DirExists (const std::string &dirName_in) |
|
int | NumFilesInDir (const std::string &dirName_in) |
|
int | NumJpgInDir (const std::string &dirName_in) |
|
ImageData | CropImage (ImageData img, int x, int y, int w, int h) |
|
ImageData | ResizeImage (ImageData img, int factor) |
|
ImageData | AddImages (ImageData img1, ImageData img2, vector2f displacement) |
|
ImageData | GaussMask (ImageData img, float sigma) |
|
ImageData | SkewImage (ImageData img, float fact) |
|
void | GetOuterEdges (float *out, int size, ImageData img) |
|
float | BackgroundMedian (ImageData img) |
|
float | BackgroundStdDev (ImageData img) |
|
float | BackgroundRMS (ImageData img) |
|
§ AddImages()
Definition at line 164 of file testutils.cpp.
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);
static TImageData alloc(int w, int h)
§ BackgroundMedian()
Definition at line 235 of file testutils.cpp.
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];
void GetOuterEdges(float *out, int size, ImageData img)
§ BackgroundRMS()
Definition at line 258 of file testutils.cpp.
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);
void GetOuterEdges(float *out, int size, ImageData img)
vector3< T > sqrt(const vector3< T > &a)
§ BackgroundStdDev()
Definition at line 249 of file testutils.cpp.
250 int size = img.
w * 2 + img.
h * 2 - 4;
251 float* outeredge =
new float[size];
void GetOuterEdges(float *out, int size, ImageData img)
T ComputeStdDev(T *data, int len)
§ CropImage()
Definition at line 132 of file testutils.cpp.
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);
static TImageData alloc(int w, int h)
§ DirExists()
bool DirExists |
( |
const std::string & |
dirName_in | ) |
|
Definition at line 12 of file testutils.cpp.
14 DWORD ftyp = GetFileAttributesA(dirName_in.c_str());
15 if (ftyp == INVALID_FILE_ATTRIBUTES)
18 if (ftyp & FILE_ATTRIBUTE_DIRECTORY)
§ distance()
Definition at line 10 of file testutils.cpp.
float distance(vector2f a, vector2f b)
§ GaussMask()
Definition at line 180 of file testutils.cpp.
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;
vector2< float > vector2f
static TImageData alloc(int w, int h)
§ GetOuterEdges()
void GetOuterEdges |
( |
float * |
out, |
|
|
int |
size, |
|
|
ImageData |
img |
|
) |
| |
Definition at line 212 of file testutils.cpp.
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);
§ NumFilesInDir()
int NumFilesInDir |
( |
const std::string & |
dirName_in | ) |
|
Definition at line 24 of file testutils.cpp.
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)){
§ NumJpgInDir()
int NumJpgInDir |
( |
const std::string & |
dirName_in | ) |
|
Definition at line 42 of file testutils.cpp.
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) {
§ ResizeImage()
Definition at line 148 of file testutils.cpp.
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);
static TImageData alloc(int w, int h)
§ SkewImage()
Definition at line 194 of file testutils.cpp.
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;
vector2< float > vector2f
static TImageData alloc(int w, int h)
float BackgroundMedian(ImageData img)
float BackgroundStdDev(ImageData img)