Beispiel #1
0
const vector< vector<double> > Gaussian::gaussianmask2D(double s, double size)
{
	sigma = s;

	//allocate some storage for our 1D mask
	mask2d.resize((int)size);
	for(int n=0; n<mask2d.size(); n++)
		mask2d[n].resize((int)size);

	//set our gaussian values
	double sum = 0;
	double center=ceil(size/2.0);
	center--;

	for(double i=0; i<size; i++)
	{
		for(double j=0; j<size; j++)
		{
			double x = i-center;
			double y = j-center;

			mask2d[(int)i][(int)j] = gaussian2d(x,y);
			sum += mask2d[(int)i][(int)j];
		}
	}

	//normalise
	for(int l=0; l<(int)size; l++)
		for(int k=0; k<(int)size; k++)
			mask2d[l][k] /=sum;

	//return the mask
	return mask2d;
}
Beispiel #2
0
void CPUbilateralFiltering(RGB* data, int width, int height,int radius, float sigma_spatial, float sigma_range)
{
    int numElements = width*height;
    RGB* res_data = (RGB *)malloc (sizeof(RGB) * width * height);
    for(int x = 0; x < width; x++)
    {
        for(int y = 0; y < height; y++)
        {
            int array_idx = y * width + x;
            RGB currentColor = data[array_idx]; //idx

            RGB res = makeColor(0.0f,0.0f,0.0f);
            RGB normalization = makeColor(0.0f,0.0f,0.0f);


            for(int i = -radius; i <= radius; i++) {
                for(int j = -radius; j <= radius; j++) {
                    int x_sample = x+i;
                    int y_sample = y+j;

                    //mirror edges
                    if( (x_sample < 0) || (x_sample >= width ) ) {
                        x_sample = x-i;
                    }

                    if( (y_sample < 0) || (y_sample >= height) ) {
                        y_sample = y-j;
                    }

                    RGB tmpColor = data[y_sample * width + x_sample];

                    float gauss_spatial = gaussian2d(i,j,sigma_spatial); //gaussian1d(i,sigma_spatial)*gaussian1d(j,sigma_spatial);//
                    RGB gauss_range;
                    gauss_range.R = gaussian1d(currentColor.R - tmpColor.R, sigma_range);
                    gauss_range.G = gaussian1d(currentColor.G - tmpColor.G, sigma_range);
                    gauss_range.B = gaussian1d(currentColor.B - tmpColor.B, sigma_range);

                    RGB weight;
                    weight.R = gauss_spatial * gauss_range.R;
                    weight.G = gauss_spatial * gauss_range.G;
                    weight.B = gauss_spatial * gauss_range.B;

                    normalization = normalization + weight;

                    res = res + (tmpColor * weight);

                }
            }

            res_data[array_idx] = res / normalization;
        }
    }

    for(int i = 0; i < numElements; i++)
    {
        data[i] = res_data[i];
    }
    free(res_data);

}
Beispiel #3
0
void Gaussian::display2d(void)
{
   double j;
 
   glColor3f(1.0,1.0,1.0);
   for(double i=-3.0*sigma; i<3.0*sigma; i+=0.1)
   {
	   glBegin(GL_LINE_STRIP);
	   for(j=-3.0*sigma; j<3.0*sigma; j+=0.1)
	   {		    
			glVertex3f(i,j,gaussian2d(i,j));
	   }
	   glEnd();

	   glBegin(GL_POINTS);
	   for(j=-3.0*sigma; j<3.0*sigma; j+=0.1)
	   {		    
			glVertex3f(i,j,gaussian2d(i,j));
	   }
	   glEnd();
   }

   glColor3f(0.0,1.0,0.0);
   glBegin(GL_LINES);
		glVertex3f(-3.0*sigma, 3.0*sigma, 0);
		glVertex3f(3.0*sigma, 3.0*sigma, 0);

		glVertex3f(-3.0*sigma, -3.0*sigma, 0);
		glVertex3f(3.0*sigma, -3.0*sigma, 0);

		glVertex3f(-3.0*sigma, -3.0*sigma, 0);
		glVertex3f(-3.0*sigma, 3.0*sigma, 0);

		glVertex3f(3.0*sigma, -3.0*sigma, 0);
		glVertex3f(3.0*sigma, 3.0*sigma, 0);
   glEnd();

}