0

I've tried getting blur done for some time now and I just can't get the border pixels to calculate properly as they continue to go out of bounds. I have noticed that at the start of the program everything goes well but roughly at j = 400 (width) calculation seem to go out of hand. It goes back to proper calculations at i = 1 (height). Anyone has an idea what am I missing here. Thank you all in advance.

// Blur image

void blur(int height, int width, RGBTRIPLE image[height][width])

{ RGBTRIPLE Temp[height][width];

int red = 0; int greenave = 0; int blueave = 0; float pixel = 0; // How many pixels to divide by.

int Redvalue  = 0;
int Greenvalue = 0;
int Bluevalue = 0;

int bottom = height - 1; int last = width - 1;

for(int i = 0; i < height; i ++) {

    for(int j = 0; j < width ; j ++)
    {


        int arrayi[3] = {i-1, i, i+1};
        int arrayj[3] = {j-1, j, j+1};

         Redvalue  = 0;
         Greenvalue = 0;
         Bluevalue = 0;
         pixel = 0;

printf("Width:%i\nHeight:%i\n",width,height);

for(int k = 0; k <= 2 ; k ++)            // i = height j = width
            {

                for(int l = 0; l <= 2 ; l ++)
                    {
                       if ((i > 1 && i <= width - 2) && (j > 1 && j <= height - 2))
                       {
                            printf("Route 1\n");
                            Redvalue += image[arrayi[k]][arrayj[l]].rgbtRed;   // Temp [array[i-1]][arrayj[j-1]] will get each pixel.!!!
                            Greenvalue += image[arrayi[k]][arrayj[l]].rgbtGreen;
                            Bluevalue += image[arrayi[k]][arrayj[l]].rgbtBlue;
                            pixel +=1;
                       }
                    else if((arrayi[k] >= 0 && arrayi[k] < width) && ((arrayj[l]) >= 0 && arrayj[l] < height))
                       {
                           printf("Route 2\n");
                           Redvalue += image[arrayi[k]][arrayj[l]].rgbtRed;   // Temp [array[i-1]][arrayj[j-1]] will get each pixel.!!!
                            Greenvalue += image[arrayi[k]][arrayj[l]].rgbtGreen;
                            Bluevalue += image[arrayi[k]][arrayj[l]].rgbtBlue;
                            pixel +=1;
                       }
                       else
                       {
                           printf("Route 3\n");
                       }

                         printf("Red: %i\tGreen: %i\tBlue: %i\nValue of i: %i\tValue of j:%i\tvalue of k:%i\tValue of l:%i\nPixel:%f\n",Redvalue,Greenvalue,Bluevalue,i,j,k,l,pixel);
                    }

        }

        Temp[i][j].rgbtRed = round(Redvalue/pixel);
        Temp[i][j].rgbtGreen = round(Greenvalue/pixel);
        Temp[i][j].rgbtBlue = round(Bluevalue/pixel);


    }


}
for(int i = 0; i < height; i ++)
{
    for(int j = 0; j < width ; j ++)
    {
        image[i][j].rgbtRed = Temp[i][j].rgbtRed;
        image[i][j].rgbtGreen = Temp[i][j].rgbtGreen;
        image[i][j].rgbtBlue = Temp[i][j].rgbtBlue;
    }
}



return;

}

You must log in to answer this question.

Browse other questions tagged .