Thread: Need help making a blur effect in c

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2020
    Posts
    1

    Need help making a blur effect in c

    I had an assignment to make a blur effect in c. I'm using a 3x3 pixel sum avarage for the blur effect. It still doesnt work right and I dont understand what im doing right. It's supposed to be running correctly. Any help would be appreciated.
    Code:
    // Blur image
    void blur(int height, int width, RGBTRIPLE image[height][width])
    {
        RGBTRIPLE sum;
        int change;
        for(int i = 0; i < height; i++)
        {
            for(int j = 0; j < width; j++)
            {
                change = 0;
                sum.rgbtRed = 0;
                sum.rgbtGreen = 0;
                sum.rgbtBlue = 0;
                for(int y = -1; y < 2; y++)
                {
                    //check if the row exists
                    if(y + i > -1 && y + i < height)
                    {
                    for(int x = -1; x < 2; x++)
                    {
                        //check if the pixel exists
                        if(x + j > -1 && x + j < width)
                        {
                            sum.rgbtRed += image[i + y][j + x].rgbtRed;
                            sum.rgbtGreen += image[i + y][j + x].rgbtGreen;
                            sum.rgbtBlue += image[i + y][j + x].rgbtBlue;
                            change++;
                        }
                    }
                    }
                }
                //if change is 0 then no pixels were found
                if(change != 0)
                    //devide the sum by number of pixels found
                    sum.rgbtRed = sum.rgbtRed / change;
                    sum.rgbtGreen = sum.rgbtGreen / change;
                    sum.rgbtBlue = sum.rgbtBlue / change;
                    image[i][j] = sum;
            }
        }
        return;
    }
    Last edited by odachi; 04-17-2020 at 09:17 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quadratic and Gaussian Blur
    By TIMBERings in forum C++ Programming
    Replies: 0
    Last Post: 09-19-2010, 06:15 PM
  2. Blur on.. skipping codings/go to.
    By cheongzewei in forum C Programming
    Replies: 4
    Last Post: 11-14-2008, 06:07 AM
  3. Motion Blur Questions
    By Sentral in forum Game Programming
    Replies: 5
    Last Post: 02-25-2006, 01:58 PM
  4. Window Drag / Blur
    By ventolin in forum Windows Programming
    Replies: 6
    Last Post: 07-26-2004, 07:27 AM
  5. Makes Me So Blur!!!
    By Mitchell in forum Windows Programming
    Replies: 1
    Last Post: 10-22-2001, 06:44 AM

Tags for this Thread