I had an assignment to make a blur effect in c. I'm using a 3x3 pixel sum avarage for the blur effect. It still doesnt work right and I dont understand what im doing right. It's supposed to be running correctly. Any help would be appreciated.
Code:
// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
RGBTRIPLE sum;
int change;
for(int i = 0; i < height; i++)
{
for(int j = 0; j < width; j++)
{
change = 0;
sum.rgbtRed = 0;
sum.rgbtGreen = 0;
sum.rgbtBlue = 0;
for(int y = -1; y < 2; y++)
{
//check if the row exists
if(y + i > -1 && y + i < height)
{
for(int x = -1; x < 2; x++)
{
//check if the pixel exists
if(x + j > -1 && x + j < width)
{
sum.rgbtRed += image[i + y][j + x].rgbtRed;
sum.rgbtGreen += image[i + y][j + x].rgbtGreen;
sum.rgbtBlue += image[i + y][j + x].rgbtBlue;
change++;
}
}
}
}
//if change is 0 then no pixels were found
if(change != 0)
//devide the sum by number of pixels found
sum.rgbtRed = sum.rgbtRed / change;
sum.rgbtGreen = sum.rgbtGreen / change;
sum.rgbtBlue = sum.rgbtBlue / change;
image[i][j] = sum;
}
}
return;
}