示例#1
0
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);
}
示例#2
0
static void rebin(float** thedata,
                  int W, int H, int S,
                  int* newW, int* newH) {
    float sigma = S;

	get_output_image_size(W, H, S, EDGE_AVERAGE, newW, newH);

    // Gaussian smooth in-place.
    dsmooth2(*thedata, W, H, sigma, *thedata);

    // Average SxS blocks, placing the result in the bottom (newW * newH) first pixels.
	if (!average_image_f(*thedata, W, H, S, EDGE_AVERAGE, newW, newH, *thedata)) {
		ERROR("Averaging the image failed.");
		return;
	}
}
示例#3
0
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);
}
示例#4
0
int main(void) {
    struct dirent **namelist;
    int i, n, N;
    unsigned char *image = NULL;
    float *image_bw_f;
    unsigned char *image_bw_u8;
    float *image_out_old;
    float *image_out_new;
    char fullpath[255];
    char outpath_old[255];
    char outpath_new[255];
    int imW, imH;

    float sigma;
    float err;

    sigma = 1.0;

    N = scandir("demo_simplexy_images", &namelist, is_input_image, alphasort);
    if (N < 0) {
        perror("scandir");
        return 1;
    }

    for (n = 0; n < N; n++) {

        strcpy(fullpath, "demo_simplexy_images/");
        strcat(fullpath, namelist[n]->d_name);

        strcpy(outpath_old, "demo_simplexy_images/out_");
        strcat(outpath_old, namelist[n]->d_name);
        outpath_old[strlen(outpath_old)-4] = '\0';
        strcat(outpath_old, "_old");
        strcat(outpath_old, ".png");

        strcpy(outpath_new, "demo_simplexy_images/out_");
        strcat(outpath_new, namelist[n]->d_name);
        outpath_new[strlen(outpath_new)-4] = '\0';
        strcat(outpath_new, "_new");
        strcat(outpath_new, ".png");

        fprintf(stderr,"demo_dsmooth: loading %s ", fullpath);

        if (is_png(namelist[n])) {
            fprintf(stderr, "as a PNG\n");
            image = cairoutils_read_png(fullpath, &imW, &imH);
        }

        if (is_jpeg(namelist[n])) {
            fprintf(stderr, "as a JPEG\n");
            image = cairoutils_read_jpeg(fullpath, &imW, &imH);
        }

        image_bw_u8 = to_bw_u8(image, imW, imH);
        image_bw_f = malloc(sizeof(float) * imW * imH);
        for (i = 0; i < imW*imH; i++) {
            image_bw_f[i] = (float)image_bw_u8[i];
        }

        image_out_old = malloc(sizeof(float)*imW*imH);
        image_out_new = malloc(sizeof(float)*imW*imH);

        fprintf(stderr,"demo_dsmooth: running %s through dsmooth\n", fullpath);
        dsmooth(image_bw_f, imW, imH, sigma, image_out_old);

        fprintf(stderr,"demo_dsmooth: running %s through dsmooth2\n", fullpath);
        dsmooth2(image_bw_f, imW, imH, sigma, image_out_new);

        err = 0.0;
        for (i = 0; i < imW*imH; i++) {
            err += fabs(image_out_old[i]-image_out_new[i]);
        }
        err = err / (imW*imH);

        fprintf(stderr, "demo_dsmooth: error between smooths: %f per pixel\n", err);

        //		fprintf(stderr, "demo_dsmooth: writing old dsmoothed image to %s\n", outpath_old);
        //		cairoutils_write_png(outpath_old, to_cairo_bw(image_out_old, imW, imH), imW, imH);

        //		fprintf(stderr, "demo_dsmooth: writing new dsmoothed image to %s\n", outpath_new);
        //		cairoutils_write_png(outpath_new, to_cairo_bw(image_out_new, imW, imH), imW, imH);

        free(namelist[n]);
        free(image);
        free(image_bw_f);
        free(image_bw_u8);
        free(image_out_old);
        free(image_out_new);

    }
    free(namelist);

    return 0;
}