0

My program when run through check50 says the corner pixels work but nothing else seems to work. I have been stuck on this problem for days and after not getting any considerable reply on the cs50 subreddit i am posting this here. I ran this through debug50 as well and the second pixel ( at I = 0 , J =1) which is supposed to be edge case took in 6 values as it is supposed to and rejected the first 3 which were invalid pixels. One point that my help is all my color values are a little larger than they are supposed to be as found on the check50 results. My code is :

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

    {
    int i = 0;
    int j = 0;  
    int a = 0;
    int b = 0;
    int k = 0;
    int g = 0;
    int r = 0;
    int bl = 0;

    while(i < height)
    {

       if(j < width)
        {
            int A[10] = {i - 1 , i - 1, i - 1 , i , i , i , i + 1 , i + 1 , i + 1};
            int B[10] = {j - 1 , j , j + 1 , j - 1 , j , j + 1 , j - 1 , j , j + 1};

                k = 0;
                g = 0;
                r = 0;
                bl = 0;

            for(int c = 0; c < 9; c++)
            {
                //to reject values wrong of i & j
                if( (A[c] < 0 || A[c] > height) || (B[c] < 0 || B[c] > width) )
                {

                }  

                else
                {
                    a = A[c];
                    b = B[c];
                    k++;
                    g = g + (int)image[a][b].rgbtGreen;
                    r = r + (int)image[a][b].rgbtRed;
                    bl = bl + (int)image[a][b].rgbtBlue;
                }
            }

                image[i][j].rgbtGreen = round((float)g/(float)k);
                image[i][j].rgbtRed = round((float)r/(float)k);
                image[i][j].rgbtBlue = round((float)bl/(float)k);


                j++;
        }


        //if the end of a row has been reached
        else
        {
            j = 0;
            i++;
        }
    }


    return;
}
0

As you advance doing the average for every pixel, and changing the values of them, in the next iterations, the values you'll be working with, won't be the original ones.

Apart from that, I'd suggest you to check the limits in your conditions. Remember that 'image[width]' is out of the limits of the RGBTRIPLE array, as it starts with 0 index.

11
  • Yes. I am reseting the values when I move to a new pixel. Once the color values for a pixel are saved, my existing values are reset to 0 in the " if(width < j)" loop. Also, I have used the "less than" sign for width and not " less than equal to" clearly keeping it within the bounds I guess. The I and j condition worked with other functions as well so I don't think I or j either are going beyond the height or width bounds – Chirayu Bhatt Jun 1 '20 at 19:27
  • Yes but in your calculations of the average of the 3x3 pixels around every pixel, you're taking pixels that are already been changed, and, in order to complete the exercise, the values have to be the original ones. – Tritum Jun 1 '20 at 19:35
  • I mistakenly uploaded a edited version of my code for which I used bebug50 and trired to stop it at middle pixel. This is my orginal code. I think this used the original values – Chirayu Bhatt Jun 2 '20 at 6:37
  • Did you use a copy of the original image to get the values?? – Tritum Jun 2 '20 at 6:46
  • I ran check 50 on it. All my values are higher than they're supposed to be – Chirayu Bhatt Jun 2 '20 at 8:24

You must log in to answer this question.

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