0

The code in helpers.c all images compiles exept for the Blur image it compiles without any errors. But doesn't pass the cs50 check? any suggestions only the Blur image section. Thanks

    // Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE temp[height][width];
    for (int m = 0; m < height; m++)
    {
        for (int n = 0; n < width; n++)
        {
            temp[m][n] = image[m][n];
        }
    }
    //
    for(int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            //
            int pixelCount = 0;
            float valRed = 0;
            float valGreen = 0;
            float valBlue = 0;

            for (int k = -1; k < 2; k++)
            {
                for (int l = -1; l < 2; l++)
                {
                    //
                    if (i + k < 0 || i + k >= height)
                    {
                        continue;
                    }
                    //
                    if (j +l < 0 || j + l >= width)
                    {
                        continue;
                    }
                    //
                    valRed += temp[i + k][j + l].rgbtRed;
                    valGreen += temp[i + k][j + l].rgbtGreen;
                    valBlue += temp[i + k][j + l].rgbtBlue;
                }
            }
            //
            image[i][j].rgbtRed = (int)round(valRed / pixelCount);
            image[i][j].rgbtGreen = (int)round(valGreen / pixelCount);
            image[i][j].rgbtBlue = (int)round(valBlue / pixelCount);
        }

    }

}

Error section form check50 on Blur image

:( blur correctly filters middle pixel
    expected "127 140 149\n", not "0 0 0\n"
:( blur correctly filters pixel on edge
    expected "80 95 105\n", not "0 0 0\n"
:( blur correctly filters pixel in corner
    expected "70 85 95\n", not "0 0 0\n"
:( blur correctly filters 3x3 image
    expected "70 85 95\n80 9...", not "0 0 0\n0 0 0\n..."
:( blur correctly filters 4x4 image
    expected "70 85 95\n80 9...", not "0 0 0\n0 0 0\n..."
0

Tried many times to fix and check Blur image section by check50 but keeps giving errors. I removed and reinstalled the filter folder, retyped code and voila check50 gave all four sections GREEN.

Results for cs50/problems/2021/x/filter/less
:) helpers.c exists
:) filter compiles
:) grayscale correctly filters single pixel with whole number average
:) grayscale correctly filters single pixel without whole number average
:) grayscale leaves alone pixels that are already gray
:) grayscale correctly filters simple 3x3 image
:) grayscale correctly filters more complex 3x3 image
:) grayscale correctly filters 4x4 image
:) sepia correctly filters single pixel
:) sepia correctly filters simple 3x3 image
:) sepia correctly filters more complex 3x3 image
:) sepia correctly filters 4x4 image
:) reflect correctly filters 1x2 image
:) reflect correctly filters 1x3 image
:) reflect correctly filters image that is its own mirror image
:) reflect correctly filters 3x3 image
:) reflect correctly filters 4x4 image
:) blur correctly filters middle pixel
:) blur correctly filters pixel on edge
:) blur correctly filters pixel in corner
:) blur correctly filters 3x3 image
:) blur correctly filters 4x4 image
~/pset4/filter/ $ 

You must log in to answer this question.

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