0

void blur(int height, int width, RGBTRIPLE image[height][width]) {

RGBTRIPLE copy[height][width];

int counter = 0;
int red = 0;
int blue = 0;
int green = 0;

for(int i=0; i<height; i++)
{
        for(int j=0; j<width; j++)

        {
          for(int k=-1; k<2; k++)
            {
                for(int l=-1; l<2; l++)
                {
                    if(i+k >=0 && i+k < height && j+l >=0 &&  j+l < width)
                    {
                        counter++;
                        red +=  image[i+k][j+l].rgbtRed;
                        blue += image[i+k][j+l].rgbtBlue;
                        green += image[i+k][j+l].rgbtGreen;
                    }
                }
            }

        float red_avg = 0;
        float blue_avg = 0;
        float green_avg = 0;

        red_avg = round(red/(float)counter);
        blue_avg = round(blue/(float)counter);
        green_avg = round(green/(float)counter);

        copy[i][j].rgbtRed = red_avg;
        copy[i][j].rgbtBlue = blue_avg;
        copy[i][j].rgbtGreen = green_avg;



    }
}

for(int i=0; i<height; i++)
{
    for(int j=0; j<width; j++)
    {

        image[i][j].rgbtRed = copy[i][j].rgbtRed;
        image[i][j].rgbtBlue = copy[i][j].rgbtBlue;
        image[i][j].rgbtGreen = copy[i][j].rgbtGreen; 

    }
}

return;

}

What I'm trying to do is to see if the adjacent points to the pixel exist and if it does then I increment the counter and the rgbt values of that pixel, then finally I calculate the average and store it to a copy of RGBTRIPLE which the initial RGBTRIPLE is then assigned to.

0

You need to reset to 0 your variables on every pixel.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .