Got stuck in Blur for more than a week and can´t find out what is wrong. I´ve tried many differents ways, but only corner values matches. Can anyone please give me a help about this.
// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width]) { RGBTRIPLE new_image[height][width]; float red = 0; float blue = 0; float green = 0;
//copying image into a new file
for (int h = 0; h < height; h++)
{
for (int w = 0; w < width; w++)
{
new_image[h][w] = image[h][w];
}
}
//h and w loops to reach all pixels in height and width
for (int h = 0; h < height; h++)
{
for (int w = 0; w < width; w++)
{
int count = 0;
//loops i & j for reach the neighbour pixels
for (int i = - 1; i < 2; i++)
{
for (int j = - 1; j < 2; j++)
{
//Condition to exclude out of edge pixels
if((h + i >= 0) && (h + i < height) && (w + j >= 0) && (w + j < width))
{
//count of valid pixels
count++;
//adding colors values to variable
red += image[h + i][w + j].rgbtRed;
blue += image[h + i][w + j].rgbtBlue;
green += image[h + i][w + j].rgbtGreen;
//coping colors values into a new image
new_image[h][w].rgbtRed = round(red / (float)count);
new_image[h][w].rgbtBlue = round(blue / (float)count);
new_image[h][w].rgbtGreen = round(green / (float)count);
}
}
}
}
}
//loop to copy the blured pixel into original image
for (int h = 0; h < height; h++)
{
for (int w = 0; w < width; w++)
{
image[h][w].rgbtRed = new_image[h][w].rgbtRed;
image[h][w].rgbtBlue = new_image[h][w].rgbtBlue;
image[h][w].rgbtGreen = new_image[h][w].rgbtGreen;
}
}
}
:( blur correctly filters middle pixel
expected "127 140 149\n", not "73 118 150\n"
:( blur correctly filters pixel on edge expected "80 95 105\n", not "127 152 168\n" :) blur correctly filters pixel in corner :( blur correctly filters 3x3 image expected "70 85 95\n80 9...", not "70 85 95\n127 ..." :( blur correctly filters 4x4 image expected "70 85 95\n80 9...", not "70 85 95\n127 ..."