0

So after I passed pset3, I thought things would go easier since my friend said that filter wasn't as complicated as Tideman. Now, I’m doing the blur filter part and stuck on its computation especially determining whether its an edge or sides.

This part of my function acts as scanner for the whole 3x3, if its outside the boundary (-1 for the left and upper side and width for right side), it’ll be skipped, otherwise it will be counted on a variable named counter as well summed by available neighboring pixels. The variable counter then will be act as their denominator for the average calculation.

Yet, after doing check50, it wont work. I dont see any fault on the logics, maybe you guys can give me hint over this problem (because then, the edge filter is only matter of computation).

This is my program, have a look.

||// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
    float counter;
    float sumRed;
    float sumGreen;
    float sumBlue;

    //Copy of image
    RGBTRIPLE copy[height][width];

    //Copy all values for dummy image
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            copy[i][j] = image [i][j];
        }
    }

    //Above copy is meant to be computed as the original one will change over loops

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

        for (int j = 0; j < width; j++)
        {
            //initialize counter
            counter = 0.0;

            //initialize sum
            sumRed = 0.0;
            sumGreen = 0.0;
            sumBlue = 0.0;

           //Checking surrounding pixels
           for (int k = i - 1; k <= i + 2; k++)
           {
               for (int l = j - 1; l <= j + 2; l++)
               {
                   if (k < 0 (or) k > height + 1 (or) l < 0 (or) l > width + 1 )
                   {

                   }
                   else
                   {
                       sumRed += copy[k][l].rgbtRed;
                       sumGreen += copy[k][l].rgbtGreen;
                       sumBlue += copy[k][l].rgbtBlue;

                       counter++;
                   }
               }
           }


            //compute new values
            image[i][j].rgbtRed = round (sumRed/counter);
            image[i][j].rgbtGreen = round (sumGreen/counter);
            image[i][j].rgbtBlue = round (sumBlue/counter);

        }

    }
    return;
}
0

You're almost there. There are only 2 small issues in your code.

  • For the first one, you should check how many iterations you get in your 'k and l' loops. As you know, there should be 3.
  • The second one has to do with the index limits. Heigth/Width indexes to be valid should be between 0 and heigth/width -1.
1
  • I have written exactly same code and was surprised to see that . But its not working too . I have not used the k<=i+2 else i wrote it as k<i+2 . – MWD Sep 9 '20 at 15:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .