iDevGames Forums
Gaussian blur - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Gaussian blur (/thread-9386.html)



Gaussian blur - g00se - Oct 3, 2011 12:58 PM

Second filter is Gaussian blur. It works kinda strange. It only changes brightness of an image, but do not blur image. Here is my code:

Code:
// Count mask 3x3
    if (size == 1) {
        for (row=-1; row<=1; row++) {
            for (col=-1; col<=1; col++) {
                midCalkulation = -((pow(col, 2) + pow(row, 2))/(2*pow(sigma, 2)));
                kernel3x3[row+1][col+1] = (1/(2*M_PI*pow(sigma, 2)))*exp(midCalkulation);
                
            }
        }
    }

    // Image convolution with filter mask
    if (size == 1) {
        for(row=1; row<height-1; row++) {
            for(col=1; col<width-1; col++) {
                midSum=0;
                for(int i=-1; i<=1; i++) {
                    for(int j=-1; j<=1; j++) {
                        midSum += pixels[(row+i)*width + (col+j)]*kernel3x3[i+1][j+1];
                    }
                }
                filteredPixels[row*width + col] = midSum;
            }
        }
    }

I can't see where I'm making a mistake. Little help needed, please. Thank in advance.