0

I am trying to blur my image but I am running into trouble. First of all, the issue is that I run out of bounds - because I did not account for edges and corners here. Is there a simple fix - like somehow setting it to ignore the ones that would go out of bounds in the event that they are out of bounds? Or do I need to restructure my entire code? And if so, how?

// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE image2[height][width];
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            {
            int blurRed = (image[i-1][j-1].rgbtRed + image[i-1][j].rgbtRed + image[i-1][j+1].rgbtRed + image[i][j-1].rgbtRed + image[i][j].rgbtRed + image[i][j+1].rgbtRed + image[i+1][j-1].rgbtRed + image[i+1][j].rgbtRed + image[i+1][j+1].rgbtRed / (i + j));
            int blurGreen = (image[i-1][j-1].rgbtGreen + image[i-1][j].rgbtGreen + image[i-1][j+1].rgbtGreen + image[i][j-1].rgbtGreen + image[i][j].rgbtGreen + image[i][j+1].rgbtGreen + image[i+1][j-1].rgbtGreen + image[i+1][j].rgbtGreen + image[i+1][j+1].rgbtGreen / (i + j));
            int blurBlue = (image[i-1][j-1].rgbtBlue + image[i-1][j].rgbtBlue + image[i-1][j+1].rgbtBlue + image[i][j-1].rgbtBlue + image[i][j].rgbtBlue + image[i][j+1].rgbtBlue + image[i+1][j-1].rgbtBlue + image[i+1][j].rgbtBlue + image[i+1][j+1].rgbtBlue /  (i + j));
            image2[i][j].rgbtRed = blurRed;
            image2[i][j].rgbtGreen = blurGreen;
            image2[i][j].rgbtBlue = blurBlue;
            }
        }
    }
    return;
}

You must log in to answer this question.

Browse other questions tagged .