I am having difficulty understanding what the next step should be for the blur function. I have rewritten the code to try to make it at least more understandable to me after a few trials, however, it still only correctly filters edge and corner pixels.
Any help would be much appreciated!
Thank you!
void blur(int height, int width, RGBTRIPLE image[height][width])
{
// Make copy to be used for reading values
RGBTRIPLE copy[height][width];
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
copy[i][j] = image[i][j];
}
}
// Loop through pixels and locate neighboring pixels
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
// Create variables to hold values and a counter value to count each pixel, set the counter variable to a float
int totalR = 0, totalG = 0, totalB = 0;
float n = 0;
// Check whether pixel is in bounds, allow program to continue if not
//Based on position relative to current pixel
for (int x = -1; x < 2; x++)
{
for (int y = -1; y < 2; y++)
{
//Check top edge
if ((i + x) < 0)
{
continue;
}
//Check bottom edge
else if ((i + x) > (height - 1))
{
continue;
}
// Check left edge
else if ((j + y) < 0)
{
continue;
}
// Check right edge
if ((j + y) > (width - 1))
{
continue;
}
// Add valid pixels
totalR += image[i + x][j + y].rgbtRed;
totalG += image[i + x][j + y].rgbtGreen;
totalB += image[i + x][j + y].rgbtBlue;
// Counter variable for all valid pixels
n++;
// Calculate image value with float, place in copy
copy[i][j].rgbtRed = round(totalR / n);
copy[i][j].rgbtGreen = round(totalG / n);
copy[i][j].rgbtBlue = round(totalB / n);
}
}
}
// Return copy to original
for ( i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
image[i][j].rgbtRed = copy[i][j].rgbtRed;
image[i][j].rgbtGreen = copy[i][j].rgbtGreen;
image[i][j].rgbtBlue = copy[i][j].rgbtBlue;
}
}
return;
}
}