Need some help with blur. I think i'm getting it entirely wrong but i can't seem to understand why. None of the blur assessment are correct at all. Wonder if anyone can give me any tips on getting the thinking right.
void blur(int height, int width, RGBTRIPLE image[height][width]) { //create another array to place a copy of these images so that can manipulate the original image RGBTRIPLE newimage[height][width]; //create variables to store the manipulated values of the image int red, green, blue, counter;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
//assign original value of the image into the replacement array for manipulation
newimage[i][j] = image[i][j];
//reset values of red,green,blue,counter for this pixel into 0
red = green = blue = counter = 0;
//for top left-most pixel
if (i == 0 && j == 0)
{
red = round ((newimage[0][0].rgbtRed + newimage[1][0].rgbtRed + newimage[1][1].rgbtRed + newimage[0][1].rgbtRed) / 4.0);
green = round ((newimage[0][0].rgbtGreen + newimage[1][0].rgbtGreen + newimage[1][1].rgbtGreen + newimage[0][1].rgbtGreen) / 4.0);
blue = round ((newimage[0][0].rgbtBlue + newimage[1][0].rgbtBlue + newimage[1][1].rgbtBlue + newimage[0][1].rgbtBlue) / 4.0);
}
//for top right-most pixel
if (i == 0 && j == (width - 1))
{
red = round((newimage[i][j].rgbtRed + newimage[i][j-1].rgbtRed + newimage[i+1][j-1].rgbtRed + newimage[i+1][j].rgbtRed) / 4.0);
green = round((newimage[i][j].rgbtGreen + newimage[i][j-1].rgbtGreen + newimage[i+1][j-1].rgbtGreen + newimage[i+1][j].rgbtGreen) / 4.0);
blue = round((newimage[i][j].rgbtBlue + newimage[i][j-1].rgbtBlue + newimage[i+1][j-1].rgbtBlue + newimage[i+1][j].rgbtBlue) / 4.0);
}
//for everything else on the top row
if ((i == 0 && j != (width - 1)) || (i == 0 && j!= 0))
{
red = round((newimage[i][j].rgbtRed + newimage[i][j - 1].rgbtRed + newimage[i + 1][j - 1].rgbtRed + newimage[i + 1][j].rgbtRed
+ newimage [i + 1][j + 1].rgbtRed + newimage[i][j+1].rgbtRed) / 6.0);
green = round((newimage[i][j].rgbtGreen + newimage[i][j - 1].rgbtGreen + newimage[i + 1][j - 1].rgbtGreen + newimage[i + 1][j].rgbtGreen
+ newimage [i + 1][j + 1].rgbtGreen + newimage[i][j+1].rgbtGreen) / 6.0);
blue = round((newimage[i][j].rgbtBlue + newimage[i][j - 1].rgbtBlue + newimage[i + 1][j - 1].rgbtBlue + newimage[i + 1][j].rgbtBlue
+ newimage [i + 1][j + 1].rgbtBlue + newimage[i][j+1].rgbtBlue) / 6.0);
}
//for bottom left pixel
if (i == height -1 && j == 0)
{
red = round((newimage[i][j].rgbtRed + newimage[i -1][j].rgbtRed + newimage[i - 1][j + 1].rgbtRed +
newimage[i][j + 1].rgbtRed) / 4.0);
green = round((newimage[i][j].rgbtGreen + newimage[i -1][j].rgbtGreen + newimage[i - 1][j + 1].rgbtGreen +
newimage[i][j + 1].rgbtGreen) / 4.0);
blue = round((newimage[i][j].rgbtBlue + newimage[i -1][j].rgbtBlue + newimage[i - 1][j + 1].rgbtBlue +
newimage[i][j + 1].rgbtBlue) / 4.0);
}
//for 1st column (for everything other than top left and bottom left pixel)
if ((j == 0 && i != 0 ) || (j == 0 && i != height - 1))
{
red = round((newimage[i][j].rgbtRed + newimage[i - 1][j].rgbtRed + newimage[i - 1][j + 1].rgbtRed + newimage[i][j + 1].rgbtRed
+ newimage[i + 1][j + 1].rgbtRed + newimage[i + 1][j].rgbtRed) / 6.0);
green = round((newimage[i][j].rgbtGreen + newimage[i - 1][j].rgbtGreen + newimage[i - 1][j + 1].rgbtGreen +
newimage[i][j + 1].rgbtGreen + newimage[i + 1][j + 1].rgbtGreen + newimage[i + 1][j].rgbtGreen) / 6.0);
blue = round((newimage[i][j].rgbtGreen + newimage[i - 1][j].rgbtGreen + newimage[i - 1][j + 1].rgbtGreen +
newimage[i][j + 1].rgbtGreen + newimage[i + 1][j + 1].rgbtGreen + newimage[i + 1][j].rgbtGreen) / 6.0);
}
//for bottom right pixel
if ( i == (height - 1) && j == (width - 1))
{
red = round((newimage[i][j].rgbtRed + newimage[i - 1][j].rgbtRed + newimage[i - 1][j - 1].rgbtRed +
newimage [i][j - 1].rgbtRed)/4.0);
green = round((newimage[i][j].rgbtGreen + newimage[i - 1][j].rgbtGreen + newimage[i - 1][j - 1].rgbtGreen +
newimage [i][j - 1].rgbtGreen)/4.0);
blue = round((newimage[i][j].rgbtBlue + newimage[i - 1][j].rgbtBlue + newimage[i - 1][j - 1].rgbtBlue +
newimage [i][j - 1].rgbtBlue)/4.0);
}
//for everything on bottom row that is not the 1st and the last row
if ((i == (height - 1) && j != 0) || (i == (height - 1) && j != (width - 1)))
{
red = round((newimage[i][j].rgbtRed + newimage[i][j - 1].rgbtRed + newimage[i - 1][j - 1].rgbtRed + newimage[i - 1][j].rgbtRed
+ newimage[i - 1][j + 1].rgbtRed + newimage[i][j + 1].rgbtRed) / 6.0);
green = round((newimage[i][j].rgbtGreen + newimage[i][j - 1].rgbtGreen + newimage[i - 1][j - 1].rgbtGreen
+ newimage[i - 1][j].rgbtGreen + newimage[i - 1][j + 1].rgbtGreen + newimage[i][j + 1].rgbtGreen) / 6.0);
blue = round((newimage[i][j].rgbtBlue + newimage[i][j - 1].rgbtBlue + newimage[i - 1][j - 1].rgbtBlue
+ newimage[i - 1][j].rgbtBlue + newimage[i - 1][j + 1].rgbtGreen + newimage[i][j + 1].rgbtGreen) / 6.0);
}
//for the last column except top right and bottom right pixel
if (( j == (width - 1) && i != 0) || (j == ((width - 1) && i == (height - 1))))
{
red = round((newimage[i][j].rgbtRed + newimage[i -1][j].rgbtRed + newimage[i -1][j - 1].rgbtRed + newimage[i][j - 1].rgbtRed
+ newimage[i + 1][j -1].rgbtRed + newimage[i + 1][j].rgbtRed) / 6.0);
green = round((newimage[i][j].rgbtGreen + newimage[i -1][j].rgbtGreen + newimage[i -1][j - 1].rgbtGreen +
newimage[i][j - 1].rgbtGreen + newimage[i + 1][j -1].rgbtGreen + newimage[i + 1][j].rgbtGreen) / 6.0);
blue = round((newimage[i][j].rgbtBlue + newimage[i -1][j].rgbtBlue + newimage[i -1][j - 1].rgbtBlue +
newimage[i][j - 1].rgbtBlue + newimage[i + 1][j -1].rgbtBlue + newimage[i + 1][j].rgbtBlue) / 6.0);
}
//for all ther pixels
if (i != 0 || i != (height - 1) || j != 0 || j != (width -1))
{
red = round((newimage[i][j].rgbtRed + newimage[i - 1][j - 1].rgbtRed + newimage[i - 1][j].rgbtRed + newimage[i - 1][j + 1].rgbtRed
+ newimage[i][j + 1].rgbtRed + newimage[i + 1][j + 1].rgbtRed + newimage[i + 1][j].rgbtRed + newimage[i + 1][j -1].rgbtRed
+ newimage[i][j -1].rgbtRed) / 10.0);
green = round((newimage[i][j].rgbtGreen + newimage[i - 1][j - 1].rgbtGreen + newimage[i - 1][j].rgbtGreen +
newimage[i - 1][j + 1].rgbtGreen + newimage[i][j + 1].rgbtGreen + newimage[i + 1][j + 1].rgbtGreen + newimage[i + 1][j].rgbtGreen
+ newimage[i + 1][j -1].rgbtGreen + newimage[i][j -1].rgbtGreen) / 10.0);
blue = round((newimage[i][j].rgbtBlue + newimage[i - 1][j - 1].rgbtBlue + newimage[i - 1][j].rgbtBlue +
newimage[i - 1][j + 1].rgbtBlue + newimage[i][j + 1].rgbtBlue + newimage[i + 1][j + 1].rgbtBlue + newimage[i + 1][j].rgbtBlue
+ newimage[i + 1][j -1].rgbtBlue + newimage[i][j -1].rgbtBlue) / 10.0);
}
image[i][j].rgbtRed = red;
image[i][j].rgbtGreen = green;
image[i][j].rgbtBlue = blue;
(added and modified) I modified the if conditions and tried to get it to work this way. Still unsure why this is not working, could someone help with viewing the if conditions please.
// Blur image void blur(int height, int width, RGBTRIPLE image[height][width]) { //create another array to place a copy of these images so that can manipulate the original image RGBTRIPLE newimage[height][width]; //create variables to store the manipulated values of the image int red, green, blue, counter;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
//assign original value of the image into the replacement array for manipulation
newimage[i][j] = image[i][j];
//reset values of red,green,blue,counter for this pixel into 0
red = green = blue = counter = 0;
//for pixel that you are looking at
if (i >= 0 && j >=0)
{
red += newimage[i][j].rgbtRed;
green += newimage[i][j].rgbtGreen;
blue += newimage[i][j].rgbtBlue;
counter++;
}
//for pixel to the top left (exclude the pixels that are on left most column and top row)
if((i != 0 && j > 0) || (i > 0 && j!= 0))
{
red += newimage[i - 1][j - 1].rgbtRed;
green += newimage[i - 1][j - 1].rgbtGreen;
blue += newimage[i - 1][j - 1].rgbtBlue;
counter++;
}
//for pixel above the one you are looking at (exclude pixels on top row)
if (i != 0 && j >= 0 )
{
red += newimage[i - 1][j].rgbtRed;
green += newimage[i - 1][j].rgbtGreen;
blue += newimage[i - 1][j].rgbtBlue;
counter++;
}
//for pixel to the top right of the one you looking at (Exclude pixels that are on the right most column and top row)
if (i != 0 && j != (width -1))
{
red += newimage[i - 1][j + 1].rgbtRed;
green += newimage[i - 1][j + 1].rgbtGreen;
blue += newimage[i - 1][j + 1].rgbtBlue;
counter++;
}
//for pixel to the right of the one you looking at (exclude pixels that are on the right most column)
if (j != (width - 1))
{
red += newimage[i][j +1].rgbtRed;
green += newimage[i][j + 1].rgbtGreen;
blue += newimage[i][j + 1].rgbtBlue;
counter++;
}
//for pixel to the bottom rght of the one you are looking at (exclude pixels that are on right most column and bottom row)
if (i != (height - 1) && j != (width - 1))
{
red += newimage[i + 1][j + 1].rgbtRed;
green += newimage[i + 1][j + 1].rgbtGreen;
blue += newimage[i + 1][j + 1].rgbtBlue;
counter++;
}
//for pixel to the bottom of the one you are looking at (exclude pixels that are on bottom row)
if (i != (height - 1))
{
red += newimage[i + 1][j].rgbtRed;
green += newimage[i + 1][j].rgbtGreen;
blue += newimage[i + 1][j].rgbtBlue;
counter++;
}
//for pixel to the bottom left of the one you ae looking at (exclude pixels that are on left most column and bottom row
if (i != (height - 1) && j != 0)
{
red += newimage[i + 1][j - 1].rgbtRed;
green += newimage[i + 1][j - 1].rgbtGreen;
blue += newimage[i + 1][j - 1].rgbtBlue;
counter++;
}
//for pixel to the left of the one you are looking at (exclude pixels that are on left most column)
if (j != 0)
{
red += newimage[i][j - 1].rgbtRed;
green += newimage[i][j - 1].rgbtGreen;
blue += newimage[i + 1][j - 1].rgbtBlue;
counter++;
}
image[i][j].rgbtRed = round (red / counter);
image[i][j].rgbtGreen = round (green / counter);
image[i][j].rgbtBlue = round (blue / counter);
}
}
return;