示例#1
0
/*----------------------------------------------------------------------------*/
int gauss_frame(my1IFrame *src, my1IFrame *dst, float sigma, float *over)
{
	my1Kernel kernel;
	/* computing MY 2D gaussian smoothing kernel */
	int loop = 0, loop2, index = 0;
	float temp = 1.0, corner;
	float mult, value;
	while(temp>THRESH)
	{
		temp = fgaussian2d(loop,loop,sigma);
		corner = temp;
		loop++;
	}
	value = 1.0/corner;

	int windowsize = (loop*2)-1;
	int count = windowsize/2;
	int length = windowsize*windowsize;
	float *pcoeff = (float*) malloc(length*sizeof(float));
	if(pcoeff==0x0)
		return -1;
	for(loop=0;loop<windowsize;loop++)
	{
		for(loop2=0;loop2<windowsize;loop2++)
		{
			if(over)
				mult = value * (int)fgaussian2d(loop-count, loop2-count, sigma);
			else
				mult = fgaussian2d(loop-count, loop2-count, sigma);
			pcoeff[index++] = mult;
		}
	}
	if(over) *over = value;

	if(createkernel(&kernel,windowsize)==0x0)
	{
		free(pcoeff);
		return -1;
	}
	setkernel(&kernel, pcoeff);
	kernel.orig_x = count;
	kernel.orig_y = count;
	free(pcoeff);

	correlate_frame(src, dst, &kernel);
	freekernel(&kernel);

	return 0;
}
示例#2
0
/*----------------------------------------------------------------------------*/
int main(int argc, char* argv[])
{
	int loop, test, windowsize, count;
	float temp;
	double *pkernel, *gkernel, *dkernel;
	double corner, thresh = 1.0/256.0, sigma = 1.0, sumall = 1.0;

	for(loop=1;loop<argc;loop++)
	{
		if(strncmp(argv[loop],"-t",2)==0)
		{
			if(get_param_int(argc,argv,&loop,&test)<0)
			{
				printf("Cannot get threshold value?\n");
				return -1;
			}
			thresh = 1.0/(double)test;
		}
		else if(strncmp(argv[loop],"-s",2)==0)
		{
			if(get_param_float(argc,argv,&loop,&temp)<0)
			{
				printf("Cannot get sigma value?\n");
				return -1;
			}
			sigma = (double)temp;
		}
	}

	loop=0;
	do
	{
		corner = fgaussian2d(loop,loop,sigma);
		if(corner>thresh)
		{
			sumall = corner;
			loop++;
		}
		else
		{
			corner = sumall;
			break;
		}
	}
	while(1);

	printf("Gaussian kernel build parameters:\n");
	printf("  Sigma: %lf, Threshold: %lf, Corner: %lf\n",sigma,thresh,corner);

	windowsize = (loop*2)-1;
	count = windowsize/2;

	gkernel = (double*) malloc(windowsize*windowsize*sizeof(double));
	dkernel = (double*) malloc(windowsize*sizeof(double));

	printf("Gaussian 1D kernel\n");
	pkernel = dkernel; sumall = 0.0;
	for(loop=0;loop<windowsize;loop++)
	{
		*pkernel = fgaussian1d(loop-count,sigma);
		sumall += *pkernel;
		pkernel++;
	}
	pkernel = dkernel;
	for(loop=0;loop<windowsize;loop++)
	{
		*pkernel /= sumall;
		printf("  %.6lf  ",*pkernel);
		pkernel++;
	}
	printf("\n");

	printf("Gaussian 2D kernel from 1D!\n");
	for(loop=0;loop<windowsize;loop++)
	{
		for(test=0;test<windowsize;test++)
		{
			printf("  %.6lf  ",(dkernel[loop]*dkernel[test]));
		}
		printf("\n");
	}

	printf("Gaussian 2D kernel (%dx%d)\n",windowsize,windowsize);
	pkernel = gkernel; sumall = 0.0;
	for(loop=0;loop<windowsize;loop++)
	{
		for(test=0;test<windowsize;test++)
		{
			*pkernel = fgaussian2d(loop-count, test-count, sigma);
			sumall += *pkernel;
			pkernel++;
		}
	}
	corner /= sumall;
	// normalize and show it!
	pkernel = gkernel;
	for(loop=0;loop<windowsize;loop++)
	{
		for(test=0;test<windowsize;test++)
		{
			*pkernel /= sumall;
			printf("  %.6lf  ",*pkernel);
			pkernel++;
		}
		printf("\n");
	}

	printf("Gaussian 2D kernel (1/%d)\n",(int)(1.0/corner));
	pkernel = gkernel;
	for(loop=0;loop<windowsize;loop++)
	{
		for(test=0;test<windowsize;test++)
		{
			printf("  %6d  ",(int)((*pkernel)/corner));
			pkernel++;
		}
		printf("\n");
	}

	free(dkernel);
	free(gkernel);
	return 0;
}