Apologises for the long post: I wanted to be as explicit in my logic as possible
The code I've written uses the following logic to box blur:
- Use nested for loop to access each pixel in
image
- Check where the pixel is - using predefined start and endpoints of rows and columns
- Change appropriate variables e.g.
count_from_i
based on where the pixel is - once the pixel's location is identified use a nested for loop with the variables set in accordance with each pixel's location
- This nested for loop goes through each appropriate surrounding pixel and adds it to the appropriate variable e.g
redsum
, if dealing with the red pixel - once the appropriate pixel is found then add all pixels of same hex colour value together and divide by the appropriate
count
of pixels. E.g. if it's a corner case then divide the summed green pixels by 4 - Then while still in my nested first loop (which goes through each pixel) I get my answer and let it equal my individual pixel
Result:
I get an image of static noise. I fail most of check50
for blur bar "blur correctly filters pixel in corner"
Any guidance would be greatly appreciated
Code:
int count;
int redsum = 0, greensum = 0, bluesum = 0;
int count_from_i, count_to_i;
int count_from_j, count_to_j;
int first_row = 0; // it's always gonna start from zero, no matter the size
int last_row = height - 1;
int first_column = 0; // it's always gonna start from zero, no matter the size
int last_column = width - 1;
for (int h = 0; h < height; h++)
{
for (int w = 0; w < width; w++)
{
// LEFT AREA FIRST
if (w == first_column) /* if pixel is first in column*/
{
if (h == first_row) /* If pixel is first in row*/
{
// TOP LEFT CORNER PIXEL
count = 4;
count_from_i = 0, count_to_i = 2;// Row
count_from_j = 0, count_to_j = 2;// Column
}
else if (h == last_row) /* if pixel is last in the row*/
{
// BOTTOM LEFT CORNER PIXEL
count = 4;
count_from_i = -1, count_to_i = 1; // Row
count_from_j = 0, count_to_j = 2; // Column
}
else
{
// LEFT SIDE PIXEL
count = 6;
count_from_i = -1, count_to_i = 2; // Row
count_from_j = 0, count_to_j = 2; // Column
}
}
else if (w == last_column) /*if pixel is last in column*/
{
if (h == first_row) /* If pixel is first in row*/
{
// TOP RIGHT CORNER PIXEL
count = 4;
count_from_i = 0, count_to_i = 2; //Row
count_from_j = -1, count_to_j = 1; // Column
}
else if (h == last_row) /*if pixel is last in the row*/
{
// BOTTOM RIGHT CORNER PIXEL
count = 4;
count_from_i = -1, count_to_i = 1; //Row
count_from_j = -1, count_to_j = 1; // Column
}
// RIGHT SIDE PIXEL
else
{
count = 6;
count_from_i = -1, count_to_i = 2; //Row
count_from_j = -1, count_to_j = 1; // Column
}
}
//=========BOTTOM (FLOOR) PIXEL============//
else if (h == last_row) /*pixel is last in the row*/
{
count = 6;
count_from_i = -1, count_to_i = 1; //Row
count_from_j = -1, count_to_j = 2; // Column
}
//=========TOP (CEILING) PIXEL============//
else if (h == first_row) /*pixel is first in the row*/
{
count = 6;
count_from_i = 0, count_to_i = 2; //Row
count_from_j = -1, count_to_j = 2; // Column
}
//============MIDDLE PIXEL==========================//
else
{
// MIDDLE PIXEL
count = 9;
count_from_i = -1, count_to_i = 2; //Row
count_from_j = -1, count_to_j = 2; //Column
}
// Where I'm putting the last part is what's screwing me!!!!!
// All of this is still happening on one pixel
for (int i = count_from_i; i < count_to_i; i++)
{
for (int j = count_from_j; j < count_to_j; j++)
{
redsum += image[h + i][w + j].rgbtRed;
greensum += image[h + i][w + j].rgbtGreen;
bluesum += image[h + i][w + j].rgbtBlue;
}
}
// See how different the values are if nothing is added back to the pixel
image[h][w].rgbtRed = (redsum/count);
image[h][w].rgbtGreen = (greensum/count);
image[h][w].rgbtBlue = (bluesum/count);
}
}
return;