Пример #1
0
int main(int argc, char *argv[]) {

    struct	timeval t1, t2, tr;
    double	elapsedTime = 0;

    if(argc<2) {
        printf("./dwt3d input.dat [level]");
        return -1;
    }

    char* fname = argv[1];
    char fname_out[50] = "dwt3d_out.dat";

    int level = 1;

    if (argc>2)
        level = atoi(argv[2]);

    int m, n, p;
    int i;
    float *img;
    float *tmp;

    // read the 3D image binary
    FILE* fin = fopen(fname, "rb");
    fread(&m, 1, sizeof(int), fin);
    fread(&n, 1, sizeof(int), fin);
    fread(&p, 1, sizeof(int), fin);

    img = (float*)calloc(n*m*p, sizeof(float));
    tmp = (float*)calloc(n*m*p, sizeof(float));

    fread (img, n*m*p, sizeof(float), fin);
    fclose(fin);

    gettimeofday(&t1, NULL);

    // 3D DWT transform, which is 2D DWT for each image slices
    //omp_set_num_threads(8);
    #pragma omp parallel for private(i)
    for (i=0; i<p; i++)
        cdf97(img+i*n*m, tmp+i*n*m, m, n, level);

    gettimeofday(&t2, NULL);
    timersub(&t1, &t2, &tr);
    printf("Execute time: %.2f sec\n", fabs(tr.tv_sec+(double)tr.tv_usec/1000000.0));

    FILE* fout = fopen(fname_out, "wb+");
    fwrite(&m,	 sizeof(int), 1, fout);
    fwrite(&n, 	 sizeof(int), 1, fout);
    fwrite(&p, 	 sizeof(int), 1, fout);
    fwrite(img,  sizeof(float), n*m*p, fout);
    fclose(fout);

    free(img);
    free(tmp);

    return 0;
}
Пример #2
0
int main(int argc, char *argv[]) {

    struct	timeval t1, t2, tr;
    double	elapsedTime = 0;

	if(argc<2) {
		printf("./dwt3d input.dat [level]");
		return -1;
	}

	char* fname = argv[1];
	char fname_out[50] = "dwt3d_out.dat";

	int level = 1;

	if (argc>2)
		level = atoi(argv[2]);

	int m, n, p;
	int i;
	float *img;
	float *tmp;

	// read the 3D image binary
	FILE* fin = fopen(fname, "rb");
	fread(&m, 1, sizeof(int), fin);
	fread(&n, 1, sizeof(int), fin);
	fread(&p, 1, sizeof(int), fin);

	img = (float*)calloc(n*m*p, sizeof(float));
	tmp = (float*)calloc(n*m*p, sizeof(float));
	
#pragma omp parallel for schedule(static, 4)
	for (i = 0; i < p; i++)
	{
		FILE* fin = fopen(fname, "rb");
		fseek (fin, 12 + sizeof(float) * n * m * i, SEEK_SET);
		fread (img + i * n * m, n * m, sizeof(float), fin);
		fclose(fin);
	}
	gettimeofday(&t1, NULL);

	// 3D DWT transform, which is 2D DWT for each image slices
#pragma omp parallel for schedule(static, 4)
	for (i=0; i<p; i++)
	{
		cdf97(img+i*n*m, tmp+i*n*m, m, n, level);
	}

	gettimeofday(&t2, NULL);
	timersub(&t1, &t2, &tr);
	printf("Execute time: %.3f sec\n", fabs(tr.tv_sec+(double)tr.tv_usec/1000000.0));

	free(img);
	free(tmp);

	return 0;
}
Пример #3
0
int main(int argc, char *argv[]) {

    struct	timeval t1, t2, tr;
    double	elapsedTime = 0;

    if(argc<2) {
        printf("./dwt2d input.bmp [level]");
        return -1;
    }

    char* fname = argv[1];
    char fname_out[50] = "dwt_out.bmp";

    int level = 1;

    if (argc>2)
        level = atoi(argv[2]);

    int N1;
    int	N2;
    int i, j;

    float *img;
    float *tmp;

    // read image from a BMP file
    int err = imread(&img, &N1, &N2, fname);
    if (err != 0) return err;

    tmp = (float*)calloc(N1*N2, sizeof(float));
    gettimeofday(&t1, NULL);

    // start 2D DWT transform
    cdf97(img, tmp, N1, N2, level);

    gettimeofday(&t2, NULL);
    timersub(&t1, &t2, &tr);
    printf("Execute time: %.2f sec\n", fabs(tr.tv_sec+(double)tr.tv_usec/1000000.0));

    // write an BMP image
    imwrite(img, N1, N2, fname_out);

    free(img);
    free(tmp);

    return 0;
}