| | |
| | | } |
| | | */ |
| | | |
| | | inline unsigned int random_gen() |
| | | { |
| | | unsigned int Num = 0; |
| | | #ifdef WIN32 |
| | | rand_s(&Num); |
| | | #else |
| | | Num = rand(); |
| | | #endif |
| | | return Num; |
| | | } |
| | | |
| | | char **get_random_paths(char **paths, int n, int m) |
| | | { |
| | | char **random_paths = calloc(n, sizeof(char*)); |
| | |
| | | int dw = (ow*jitter); |
| | | int dh = (oh*jitter); |
| | | |
| | | int pleft = rand_uniform(-dw, dw); |
| | | int pright = rand_uniform(-dw, dw); |
| | | int ptop = rand_uniform(-dh, dh); |
| | | int pbot = rand_uniform(-dh, dh); |
| | | int pleft = rand_uniform_strong(-dw, dw); |
| | | int pright = rand_uniform_strong(-dw, dw); |
| | | int ptop = rand_uniform_strong(-dh, dh); |
| | | int pbot = rand_uniform_strong(-dh, dh); |
| | | |
| | | int swidth = ow - pleft - pright; |
| | | int sheight = oh - ptop - pbot; |
| | |
| | | |
| | | void *load_thread(void *ptr) |
| | | { |
| | | srand(time(0)); |
| | | //srand(time(0)); |
| | | //printf("Loading data: %d\n", random_gen()); |
| | | load_args a = *(struct load_args*)ptr; |
| | | if(a.exposure == 0) a.exposure = 1; |
| | |
| | | |
| | | void *load_threads(void *ptr) |
| | | { |
| | | srand(time(0)); |
| | | //srand(time(0)); |
| | | int i; |
| | | load_args args = *(load_args *)ptr; |
| | | if (args.threads == 0) args.threads = 1; |
| | |
| | | |
| | | void random_distort_image(image im, float hue, float saturation, float exposure) |
| | | { |
| | | float dhue = rand_uniform(-hue, hue); |
| | | float dhue = rand_uniform_strong(-hue, hue); |
| | | float dsat = rand_scale(saturation); |
| | | float dexp = rand_scale(exposure); |
| | | distort_image(im, dhue, dsat, dexp); |
| | |
| | | max = swap; |
| | | } |
| | | return ((float)rand()/RAND_MAX * (max - min)) + min; |
| | | //return (random_float() * (max - min)) + min; |
| | | } |
| | | |
| | | float rand_scale(float s) |
| | | { |
| | | float scale = rand_uniform(1, s); |
| | | if(rand()%2) return scale; |
| | | float scale = rand_uniform_strong(1, s); |
| | | if(random_gen()%2) return scale; |
| | | return 1./scale; |
| | | } |
| | | |
| | |
| | | return t; |
| | | } |
| | | |
| | | unsigned int random_gen() |
| | | { |
| | | unsigned int rnd = 0; |
| | | #ifdef WIN32 |
| | | rand_s(&rnd); |
| | | #else |
| | | rnd = rand(); |
| | | #endif |
| | | return rnd; |
| | | } |
| | | |
| | | float random_float() |
| | | { |
| | | #ifdef WIN32 |
| | | return ((float)random_gen() / (float)UINT_MAX); |
| | | #else |
| | | return ((float)random_gen() / (float)RAND_MAX); |
| | | #endif |
| | | } |
| | | |
| | | float rand_uniform_strong(float min, float max) |
| | | { |
| | | if (max < min) { |
| | | float swap = min; |
| | | min = max; |
| | | max = swap; |
| | | } |
| | | return (random_float() * (max - min)) + min; |
| | | } |
| | |
| | | char *find_char_arg(int argc, char **argv, char *arg, char *def); |
| | | int sample_array(float *a, int n); |
| | | void print_statistics(float *a, int n); |
| | | unsigned int random_gen(); |
| | | float random_float(); |
| | | float rand_uniform_strong(float min, float max); |
| | | |
| | | #endif |
| | | |