Quadratic and Gaussian Blur

This is a discussion on Quadratic and Gaussian Blur within the C++ Programming forums, part of the General Programming Boards category; This is a paint like program, where on a click or drag, a circle with certain fills will appear. I'm ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    44

    Quadratic and Gaussian Blur

    This is a paint like program, where on a click or drag, a circle with certain fills will appear.

    I'm having issues with the Quadratic and Gaussian Brushes. Each provide me with a small dot, the QuadraticBush is about 20 pixels in diameter and the GaussianBrush is 1 pixel. Each start with a radius and flow of 128. These are the two functions that create the mask which stores the flow.

    They are wrapped in a double for loop holding i as each row and j as each column.

    Size is the width and height of the array.
    Distance is the distance from the click location to each pixel in the mask.
    Flow can be from 0 to 255 and represents the amount of color applied.
    Rho is some constant for the Gaussian equation.

    Quadratic:
    Code:
    if( distance <= (double)radius )  {
    	if (distance < 1) {
    		m_mask[i*(size-1)+j] = m_flow;
    	} else {
    		m_mask[i*(size-1)+j] = m_flow / (distance * distance);
    		if (m_mask[i*(size-1)+j] > m_flow) {
    			m_mask[i*(size-1)+j] = m_flow;
    		}
    	}
    } else {
    	m_mask[i*(size-1)+j] = 0;
    }

    Gaussian:
    Code:
    if( distance <= (double)radius )  {
    	float base = 1 /(2 * PI * rho * rho);
    	float exponent = -1.0 * ((distance * distance) / (2.0 * rho * rho));
    	m_mask[i*(size-1)+j] = m_flow * base * exp(exponent);
    	if (m_mask[i*(size-1)+j] > m_flow) {
    		m_mask[i*(size-1)+j] = m_flow;
    	}
    } else {
    	m_mask[i*(size-1)+j] = 0;
    }
    This is a linear blur which works just fine. It goes from 100% inside and 0% outside.

    Linear:
    Code:
    	int radius = m_radius;
    	int size = radius*2 +1;
    	int count=0;
    	int arraysize = size * size;
    	m_mask = new float[arraysize];
    	double distance;
    	for(int i=0; i<size; i++) {
    		for(int j=0; j<size; j++) {
    			distance = sqrt((double)((radius-i)*(radius-i) + (radius-j)*(radius-j)));
    			if( distance <= (double)radius )  {
    				m_mask[i*(size-1)+j] = ((radius-distance)/(double)radius) * m_flow;
    			} else {
    				m_mask[i*(size-1)+j] = 0;
    			}
    		}
    	}
    Any help would be great.
    Last edited by TIMBERings; 09-19-2010 at 06:19 PM. Reason: clarification on variables

Popular pages Recent additions subscribe to a feed

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21