requesting help for my blur function. For each pixel, i have split it into 3 for loops. One calculating the row above, same row, and row below. In each loop , if the row is smaller than 0 or equal to the height, I have used the break command to exit the loop. Whereas for the columns, if the columns are <0 or equal to the width, I used continue to skip the addition of all the values. My logic seems correct, but I cant seem to figure out what is wrong :X
void blur(int height, int width, RGBTRIPLE image[height][width])
{
int i, j, row, column, counter;
float blue, green, red, numbox;
for (i = 0; i < height; i++)
{
for (j = 0; j < width; j++) //for each pixel
{
blue = 0;
green = 0;
red = 0;
numbox = 0;
for (row = i - 1, column = j - 1, counter = 0; counter < 3; counter++, column++) // row above
{
if (row < 0)
{
break;
}
if (column < 0 || column >= width)
{
continue;
}
blue += image[row][column].rgbtBlue;
red += image[row][column].rgbtRed;
green += image[row][column].rgbtGreen;
numbox++;
}
for (row = i, column = j - 1, counter = 0; counter < 3; counter++, column++) // row above
{
if (column < 0 || column >= width)
{
continue;
}
blue += image[row][column].rgbtBlue;
red += image[row][column].rgbtRed;
green += image[row][column].rgbtGreen;
numbox++;
}
for (row = i + 1, column = j - 1, counter = 0; counter < 3; counter++, column++) // row above
{
if (row >= height)
{
break;
}
if (column < 0 || column >= width)
{
continue;
}
blue += image[row][column].rgbtBlue;
red += image[row][column].rgbtRed;
green += image[row][column].rgbtGreen;
numbox++;
}
blue /= numbox;
red /= numbox;
green /= numbox;
image[i][j].rgbtBlue = (int) round(blue);
image[i][j].rgbtRed = (int) round(red);
image[i][j].rgbtGreen = (int) round(green);
}
}
return;
}
I would greatly appreciate any insight or assistance. Thank you!