void test_dsmooth2_inplace(CuTest* tc) { float* img; int nx, ny; float* smooth1; float* smooth2; float sigma; int bites; float eps; nx = 20; ny = 19; sigma = 2.0; eps = 1e-6; bites = nx * ny * sizeof(float); img = random_image(nx, ny); smooth1 = calloc(bites, 1); smooth2 = calloc(bites, 1); dsmooth2(img, nx, ny, sigma, smooth2); // test: can we smooth in-place with dsmooth2? memcpy(smooth1, img, bites); CuAssertIntEquals(tc, 0, compare_images(img, smooth1, nx, ny, 0.0)); dsmooth2(smooth1, nx, ny, sigma, smooth1); CuAssertIntEquals(tc, 0, compare_images(smooth1, smooth2, nx, ny, eps)); free(img); free(smooth1); free(smooth2); }
void init(char* image_path) { srand(time(0)); int image_tex = texture_load(image_path); if(!image_tex) { fprintf(stderr, "texture load failed\n"); exit(1); } // get the target image base_image = image_from_tex(image_tex); population_size = INIT_POP_SIZE; pop_select = population_size * POP_SELECT_FACTOR; // create initial population fprintf(stderr, "seeding initial population..."); population = s_malloc(population_size * sizeof(t_image*)); for(int i = 0; i < population_size; i++) { population[i] = random_image(base_image->width, base_image->height); } qsort(population, population_size, sizeof(t_image*), image_fitness_cmp); best_image = image_copy(population[0]); last_best = image_fitness(population[0]); fprintf(stderr, "done\n"); }
void test_dsmooth_vs_dsmooth2(CuTest* tc) { float* img; float* img_orig; int nx, ny; float* smooth1; float* smooth2; float sigma; int bites; float eps; nx = 20; ny = 19; sigma = 2.0; eps = 1e-6; bites = nx * ny * sizeof(float); img = random_image(nx, ny); img_orig = calloc(bites, 1); memcpy(img_orig, img, bites); CuAssertIntEquals(tc, 0, compare_images(img, img_orig, nx, ny, 0.0)); smooth1 = calloc(bites, 1); smooth2 = calloc(bites, 1); dsmooth(img, nx, ny, sigma, smooth1); // test: don't change the input image CuAssertIntEquals(tc, 0, compare_images(img, img_orig, nx, ny, 0.0)); dsmooth2(img, nx, ny, sigma, smooth2); // test: don't change the input image CuAssertIntEquals(tc, 0, compare_images(img, img_orig, nx, ny, 0.0)); // test: dsmooth == dsmooth2 CuAssertIntEquals(tc, 0, compare_images(smooth1, smooth2, nx, ny, eps)); free(img); free(img_orig); free(smooth1); free(smooth2); }