I have been working on the blur function for PSET4 and when i test the function, the provided picture is blurred but i still get a few errors when i run check50. See link to check50's results:
Check50: https://submit.cs50.io/check50/953fd88ff79766cfdccb1552ded6e7f3a9eccf92
Sorry for length of the function, i couldn't find a more efficient way to solve the problem.
void blur(int height, int width, RGBTRIPLE image[height][width])
{
int new_red , new_blue , new_green , counter;
///copying images into a new array
RGBTRIPLE imageO[height][width];
for (int i = 0 ; i < height ; i++)
for (int j = 0 ; j < width; j++)
{
imageO[i][j] = image[i][j];
}
///looping over copied imaged and storing values into variables: new_red , new_blue , new_green
for(int i = 0 ; i < height ; i++)
for(int j = 0; j < width ; j++)
{
counter = 0;
new_red = 0;
new_blue = 0;
new_green = 0;
///adding right pixel
if(j == 0)
{
new_red = imageO[i][j + 1].rgbtRed + imageO[i][j].rgbtRed;
new_green = imageO[i][j + 1].rgbtGreen + imageO[i][j].rgbtGreen;
new_blue = imageO[i][j + 1].rgbtBlue + imageO[i][j].rgbtBlue;
counter = 2.0;
}
// adding left pixel
if(j == width - 1 )
{
new_red = imageO[i][j - 1].rgbtRed + imageO[i][j].rgbtRed;
new_green = imageO[i][j - 1].rgbtGreen + imageO[i][j].rgbtRed;
new_blue = imageO[i][j - 1].rgbtBlue + imageO[i][j].rgbtRed;
counter = 2.0;
}
// adding right and left pixel
if((j > 0 ) && (j < width -1))
{
new_red = imageO[i][j + 1 ].rgbtRed + imageO[i][j - 1 ].rgbtRed + imageO[i][j].rgbtRed;
new_green = imageO[i][j + 1 ].rgbtGreen + imageO[i][j - 1 ].rgbtGreen + imageO[i][j].rgbtGreen;
new_blue = imageO[i][j + 1 ].rgbtBlue + imageO[i][j - 1 ].rgbtBlue + imageO[i][j].rgbtBlue;
counter = 3.0;
}
//adding pixels above and to the right
if((i > 0) && (j == 0))
{
new_red += imageO[i - 1][j].rgbtRed + imageO[i - 1][j + 1].rgbtRed;
new_green += imageO[i - 1][j].rgbtGreen + imageO[i - 1][j + 1].rgbtGreen;
new_blue += imageO[i - 1][j].rgbtBlue + imageO[i - 1][j + 1].rgbtBlue;
counter += 2.0 ;
}
//adding pixels above and to the left
if((i > 0) && (j == width - 1 ))
{
new_red += imageO[i - 1][j].rgbtRed + imageO[i - 1][j - 1].rgbtRed;
new_green += imageO[i - 1][j].rgbtGreen + imageO[i - 1][j - 1].rgbtGreen;
new_blue += imageO[i - 1][j].rgbtBlue + imageO[i - 1][j - 1].rgbtBlue;
counter += 2.0;
}
//adding pixels above to the right and left
if((i > 0 ) && (j > 0 && j < width - 1))
{
new_red += imageO[i - 1][j].rgbtRed + imageO[i - 1][j - 1].rgbtRed + imageO[i - 1][j + 1].rgbtRed;
new_green += imageO[i - 1][j].rgbtGreen + imageO[i - 1][j - 1].rgbtGreen + imageO[i - 1][j + 1].rgbtGreen;
new_blue += imageO[i - 1][j].rgbtBlue + imageO[i - 1][j - 1].rgbtBlue + imageO[i - 1][j + 1].rgbtBlue;
counter += 3.0;
}
///adding pixels below and to the right and left
if((i < height - 1) && (j > 0 && j < width - 1))
{
new_red += imageO[i + 1][j].rgbtRed + imageO[i + 1][j - 1].rgbtRed + imageO[i + 1][j + 1].rgbtRed;
new_green += imageO[i + 1][j].rgbtGreen + imageO[i + 1][j - 1].rgbtGreen + imageO[i + 1][j + 1].rgbtGreen;
new_blue += imageO[i + 1][j].rgbtBlue + imageO[i + 1][j - 1].rgbtBlue + imageO[i + 1][j + 1].rgbtBlue;
counter += 3.0;
}
///adding pixels below and to the right
if((i < height - 1) && (j == 0))
{
new_red += imageO[i + 1][j].rgbtRed +imageO[i + 1][j + 1].rgbtRed;
new_green += imageO[i + 1][j].rgbtGreen +imageO[i + 1][j + 1].rgbtGreen;
new_blue += imageO[i + 1][j].rgbtBlue +imageO[i + 1][j + 1].rgbtBlue;
counter += 2.0;
}
//adding pixles below and to the left
if((i < height - 1) && (j == width - 1))
{
new_red += imageO[i + 1][j].rgbtRed +imageO[i + 1][j - 1].rgbtRed;
new_green += imageO[i + 1][j].rgbtGreen +imageO[i + 1][j - 1].rgbtGreen;
new_blue += imageO[i + 1][j].rgbtBlue +imageO[i + 1][j - 1].rgbtBlue;
counter += 2.0;
}
image[i][j].rgbtBlue = round(new_blue/counter);
image[i][j].rgbtGreen = round(new_green/counter);
image[i][j].rgbtRed = round(new_red/counter);
}
return;
}