Home > Net >  Trying to blurr an image in C but whole row is blured same way
Trying to blurr an image in C but whole row is blured same way

Time:08-19

So I am trying to make a function that blurs an image, basically checks all pixels around it by 1 if there is adds to counter and divides total RGB and for some reason my picture comes out like this: and idk what is happening blurred result , I think the image is blurring whole row using same value? why is that?

// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE temp[height][width];

    for(int i = 0; i < height; i  )
    {
        for(int j = 0; j < width; j  )
        {
            float totalRed,totalGreen,totalBlue;
            totalRed = totalGreen = totalBlue = 0;
            float counter = 0.00;

            //close pixels
            for(int x = -1; x < 2; x  )
            {
                for(int y = -1; y < 2; y  )
                {
                    int nbrX = i   x;
                    int nbrY = i   y;

                    if (nbrX < 0 || nbrX > (height - 1) || nbrY < 0 || nbrY > (width - 1))
                    {
                        continue;
                    }
                    totalRed  = image[nbrX][nbrY].rgbtRed;
                    totalGreen  = image[nbrX][nbrY].rgbtGreen;
                    totalBlue  = image[nbrX][nbrY].rgbtBlue;

                    counter  ;

                }


                temp[i][j].rgbtRed = round(totalRed/ counter);
                temp[i][j].rgbtGreen = round(totalGreen/ counter);
                temp[i][j].rgbtBlue = round(totalBlue/ counter);
            }

        }
    }
    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;
        }
    }
}

CodePudding user response:

Because your variables for x/y-coordinates of the "nearby"-pixel both use "i" as reference..

int nbrX = j   x;
int nbrY = i   y;

(I'd rather have made a comment - but without reputation..)

  • Related