I am stuck in Pset4-Filter/less the Blur function in particular. My problem is the image blurred correctly but does not pass check50.
Check50 result :
:( blur correctly filters middle pixel >> expected : 127 140 149 and actual : 147 162 171
:( blur correctly filters pixel on edge >> expected : 80 95 105 and actual : 90 106 116
:( blur correctly filters 3x3 image >>
Expected Output:
70 85 95
80 95 105
90 105 115
117 130 140
127 140 149
137 150 159
163 178 188
170 185 194
178 193 201
Actual Output:
70 85 95
90 106 116
120 136 146
135 150 160
147 162 171
142 155 163
128 125 132
120 126 125
93 98 122
:( blur correctly filters 4x4 image >>
Expected Output:
70 85 95
80 95 105
100 115 125
110 125 135
113 126 136
123 136 145
142 155 163
152 165 173
113 119 136
143 151 164
156 166 171
180 190 194
113 112 132
155 156 171
169 174 177
203 207 209
Actual Output:
70 85 95
90 106 116
108 124 134
131 146 156
132 147 156
142 156 166
157 172 180
154 163 177
121 125 141
143 148 162
156 163 169
136 139 171
94 94 98
142 117 140
158 156 164
123 124 179
my code :
void blur(int height, int width, RGBTRIPLE image[height][width])
{
for( int i = 0; i < height ; i++)
{
for( int j = 0; j < width ; j++)
{
// variables to store for new value for each color
// count valid pixels to count average
int sumR = 0, sumG = 0, sumB = 0, count = 0;
// available pixels for each pixel
int indexs[9][2] = {
{i-1, j-1}, {i-1, j}, {i-1, j+1},
{i, j-1}, {i, j}, {i, j+1},
{i+1, j-1}, {i+1, j}, {i+1, j+1}
};
for( int k = 0; k < 9; k++)
{
// only add valid pixels considering corner and edge pixels
if( indexs[k][0] >= 0 && indexs[k][0] <= height && indexs[k][1] >= 0 && indexs[k][1] <= width)
{
// current valid pixel
RGBTRIPLE currentImg = image[indexs[k][0]][indexs[k][1]];
// add current pixel color values to corresponding color variable
sumR += currentImg.rgbtRed;
sumB += currentImg.rgbtBlue;
sumG += currentImg.rgbtGreen;
// increase valid pixels count
count++;
}
}
// set new pixel color value
image[i][j].rgbtRed = round(sumR/ (float) count);
image[i][j].rgbtBlue = round(sumB/ (float) count);
image[i][j].rgbtGreen = round(sumG/ (float) count);
}
}
}