0
  void blur(int height, int width, RGBTRIPLE image[height][width])
{
    //A box blur
    //take the average of the surrounding pixels (1 row and 1 column away)
    //Store all the surrounding and find the averages then assign to the center
    float nearby;
    float redCount;
    float greenCount;
    float blueCount;
    RGBTRIPLE temp[height][width];
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            //Height and Width are already defined so just check for our 8 case
            //Technically 9 but will use an else for that procedure
            //top left corner
            if (i == 0 && j == 0)
            {
                 redCount = image[i][j + 1].rgbtRed + image[i + 1][j + 1].rgbtRed + image[i + 1][j].rgbtRed;
                 greenCount = image[i][j + 1].rgbtGreen + image[i+ 1][j + 1].rgbtGreen + image[i + 1][j].rgbtGreen;
                 blueCount = image[i][j + 1].rgbtBlue + image[i + 1][j + 1].rgbtBlue + image[i + 1][j].rgbtBlue;
                nearby = 4.0;
            }
            else if (i == 0 && j != width)
            {
                 redCount = image[i][j + 1].rgbtRed + image[i + 1][j + 1].rgbtRed + image[i + 1][j].rgbtRed + image[i + 1][j - 1].rgbtRed + image[i][j - 1].rgbtRed;
                 greenCount = image[i][j + 1].rgbtGreen + image[i + 1][j + 1].rgbtGreen + image[i + 1][j].rgbtGreen + image[i + 1][j - 1].rgbtGreen + image[i][j - 1].rgbtGreen;
                 blueCount = image[i][j + 1].rgbtBlue + image[i + 1][j + 1].rgbtBlue + image[i + 1][j].rgbtBlue + image[i + 1][j - 1].rgbtBlue + image[i][j - 1].rgbtBlue;
                nearby = 6.0;
            }
            else if (i == 0 && j == width - 1)
            {
                 redCount = image[i + 1][j].rgbtRed + image[i + 1][j - 1].rgbtRed + image[i][j - 1].rgbtRed;
                 greenCount = image[i + 1][j].rgbtGreen + image[i + 1][j - 1].rgbtGreen + image[i][j - 1].rgbtGreen;
                 blueCount = image[i + 1][j].rgbtBlue + image[i + 1][j - 1].rgbtBlue + image[i][j - 1].rgbtBlue;
                nearby = 4.0;
            }
            else if (i != 0 && j == 0)
            {
                 redCount = image[i - 1][j].rgbtRed + image[i - 1][j + 1].rgbtRed + image[i][j + 1].rgbtRed + image[i + 1][j + 1].rgbtRed + image[i + 1][j].rgbtRed;
                 greenCount = image[i - 1][j].rgbtGreen + image[i - 1][j + 1].rgbtGreen + image[i][j + 1].rgbtGreen + image[i + 1][j + 1].rgbtGreen + image[i + 1][j].rgbtGreen;
                 blueCount = image[i - 1][j].rgbtBlue + image[i - 1][j + 1].rgbtBlue + image[i][j + 1].rgbtBlue + image[i + 1][j + 1].rgbtBlue + image[i + 1][j].rgbtBlue;
                nearby = 6.0;
            }
            else if (i != 0 && j == width - 1)
            {
                 redCount = image[i - 1][j].rgbtRed + image[i - 1][j - 1].rgbtRed + image[i][j - 1].rgbtRed + image[i + 1][j - 1].rgbtRed + image[i + 1][j].rgbtRed;
                 greenCount = image[i - 1][j].rgbtGreen + image[i - 1][j - 1].rgbtGreen + image[i][j - 1].rgbtGreen + image[i + 1][j - 1].rgbtGreen + image[i + 1][j].rgbtGreen;
                 blueCount = image[i - 1][j].rgbtBlue + image[i - 1][j - 1].rgbtBlue + image[i][j - 1].rgbtBlue + image[i + 1][j - 1].rgbtBlue + image[i + 1][j].rgbtBlue;
                nearby = 6.0;
            }
            else if (i == height - 1 && j == 0)
            { 
                 redCount = image[i - 1][j].rgbtRed + image[i - 1][j + 1].rgbtRed + image[i][j + 1].rgbtRed;
                 greenCount = image[i - 1][j].rgbtGreen + image[i - 1][j + 1].rgbtGreen + image[i][j + 1].rgbtGreen;
                 blueCount = image[i - 1][j].rgbtBlue + image[i - 1][j + 1].rgbtBlue + image[i][j + 1].rgbtBlue;
                nearby = 4.0;
            }
            else if (i == height - 1 && j != width - 1)
            {
                 redCount = image[i - 1][j].rgbtRed + image[i - 1][j - 1].rgbtRed + image[i - 1][j].rgbtRed + image[i - 1][j + 1].rgbtRed + image[i][j + 1].rgbtRed;
                 greenCount = image[i - 1][j].rgbtGreen + image[i - 1][j - 1].rgbtGreen + image[i - 1][j].rgbtGreen + image[i - 1][j + 1].rgbtGreen + image[i][j + 1].rgbtGreen;
                 blueCount = image[i - 1][j].rgbtBlue + image[i - 1][j - 1].rgbtBlue + image[i - 1][j].rgbtBlue + image[i - 1][j + 1].rgbtBlue + image[i][j + 1].rgbtBlue;
                nearby = 6.0;
            }
            else if (i == height - 1 && j == width - 1)
            { 
                 redCount = image[i - 1][j].rgbtRed + image[i - 1][j - 1].rgbtRed + image[i][j - 1].rgbtRed;
                 greenCount = image[i - 1][j].rgbtGreen + image[i - 1][j - 1].rgbtGreen + image[i][j - 1].rgbtGreen;
                 blueCount = image[i - 1][j].rgbtBlue + image[i - 1][j - 1].rgbtBlue + image[i][j - 1].rgbtBlue;
                nearby = 4.0;
            }
            else
            {
                 redCount = image[i - 1][j].rgbtRed + image[i - 1][j - 1].rgbtRed + image[i - 1][j].rgbtRed + image[i - 1][j + 1].rgbtRed + image[i][j + 1].rgbtRed + image[i + 1][j + 1].rgbtRed + image[i + 1][j].rgbtRed + image[i + 1][j - 1].rgbtRed;
                 greenCount = image[i - 1][j].rgbtGreen + image[i - 1][j - 1].rgbtGreen + image[i - 1][j].rgbtGreen + image[i - 1][j + 1].rgbtGreen + image[i][j + 1].rgbtGreen + image[i + 1][j + 1].rgbtGreen + image[i + 1][j].rgbtGreen + image[i + 1][j - 1].rgbtGreen;
                 blueCount = image[i - 1][j].rgbtBlue + image[i - 1][j - 1].rgbtBlue + image[i - 1][j].rgbtBlue + image[i - 1][j + 1].rgbtBlue + image[i][j + 1].rgbtBlue + image[i + 1][j + 1].rgbtBlue + image[i + 1][j].rgbtBlue + image[i + 1][j - 1].rgbtBlue;
                nearby = 9.0;
            }
        //Calculate the average and assign
             redCount = ((redCount + image[i][j].rgbtRed) / nearby);
             greenCount = ((greenCount + image[i][j].rgbtGreen) / nearby);
             blueCount = ((blueCount + image[i][j].rgbtBlue) / nearby);
            temp[i][j].rgbtRed = redCount;
            temp[i][j].rgbtGreen = greenCount;
            temp[i][j].rgbtBlue = blueCount;
        }
    }
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            image[i][j].rgbtRed = temp[i][j].rgbtRed;
            image[i][j].rgbtGreen = temp[i][j].rgbtGreen;
            image[i][j].rgbtBlue = temp[i][j].rgbtBlue;
        }
    }
    return;
}
  • Many of your 'i' an 'j' indexes inside the if conditions are wrong. In some of them you're not getting he correct number of pixels. – Tritum Jun 11 at 18:38
  • Yeah funny enough I just got my first all green from correcting them. It turned out I had a lot of small mistakes that logically didnt make sense – RushT Jun 11 at 19:02

You must log in to answer this question.

Browse other questions tagged .