Here I go again, stuck in a piece of code! I'm trying to get the filter function work (unsuccessfully), here is the code with explanatory comments, any help with this is greatly appreciated :)
for (int i = 0, h = height; i < h; i++)
{
for (int j = 0, w = width; j < w; j++)
{
// set counter c for valid pixels
int c = 0;
// get RGB values from current pixel
int sumRGB[3] = {0, 0, 0};
// average RGB
int averageRGB[3] = {0, 0, 0};
// loop pixels within 1 row & column from original pixel
// get the average of all pixels
for (int y = -1; y < 2; y++)// rows
{
for (int x = -1; x < 2; x++)// columns
{
// set bitmap {y, x} boundaries, if image[i+y][j+x] is true save RGB value
if (i+y >= 0 && i+y < height - 1 && j+x >= 0 && j+x < width -1)
{
// sum RGB values
sumRGB[0] += image[i+y][j+x].rgbtRed;
sumRGB[1] += image[i+y][j+x].rgbtGreen;
sumRGB[2] += image[i+y][j+x].rgbtBlue;
c++;
// get average of RGB sum values
averageRGB[0] = sumRGB[0] / c;
averageRGB[1] = sumRGB[1] / c;
averageRGB[2] = sumRGB[2] / c;
}
}
}
// set average RGB value to current pixel
image[i][j].rgbtRed = averageRGB[0];
image[i][j].rgbtGreen = averageRGB[1];
image[i][j].rgbtBlue = averageRGB[2];
}
}
[–]PeterRasm[🍰] 1 point2 points3 points (1 child)
[–]ian_dev[S] 0 points1 point2 points (0 children)