0

I am stuck at pset4 filer-less, blur function. The duck and chatgpt say that my code is correct but it doesn't give excepted outputs in any of Check50 result for blur function.


//Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE copy[height][width];
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            copy[i][j] = image[i][j];
        }
    }

    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            image[i][j] = average(height, width, i, j, copy);
        }
    }

    return;
}

RGBTRIPLE average(int height, int width, int a, int b, RGBTRIPLE copy[height][width])
{
    RGBTRIPLE avg = {0}; // Initialize avg to zero
    int n = 0;
    for (int i = a - 1; i <= a + 1; i++)
    {
        for (int j = b - 1; j <= b + 1; j++)
        {
            if (i >= 0 && i < height && j >= 0 && j < width)
            {
                avg.rgbtRed += copy[i][j].rgbtRed;
                avg.rgbtGreen += copy[i][j].rgbtGreen;
                avg.rgbtBlue += copy[i][j].rgbtBlue;
                n++;
            }
        }
    }
    avg.rgbtRed /= n;
    avg.rgbtGreen /= n;
    avg.rgbtBlue /= n;
    return avg;
}

:( blur correctly filters pixel on edge Cause expected "80 95 105\n", not "37 9 19\n"

Log testing with sample 3x3 image first row: (10, 20, 30), (40, 50, 60), (70, 80, 90) second row: (110, 130, 140), (120, 140, 150), (130, 150, 160) third row: (200, 210, 220), (220, 230, 240), (240, 250, 255) running ./testing 3 1... checking for output "80 95 105\n"...

Expected Output: 80 95 105 Actual Output: 37 9 19 :( blur correctly filters pixel in corner Cause expected "70 85 95\n", not "6 21 31\n"

Log testing with sample 3x3 image first row: (10, 20, 30), (40, 50, 60), (70, 80, 90) second row: (110, 130, 140), (120, 140, 150), (130, 150, 160) third row: (200, 210, 220), (220, 230, 240), (240, 250, 255) running ./testing 3 2... checking for output "70 85 95\n"...

Expected Output: 70 85 95 Actual Output: 6 21 31 :( blur correctly filters 3x3 image Cause expected "70 85 95\n80 9...", not "6 21 31\n37 9 ..."

Log testing with sample 3x3 image first row: (10, 20, 30), (40, 50, 60), (70, 80, 90) second row: (110, 130, 140), (120, 140, 150), (130, 150, 160) third row: (200, 210, 220), (220, 230, 240), (240, 250, 255) running ./testing 3 3... checking for output "70 85 95\n80 95 105\n90 105 115\n117 130 140\n127 140 149\n137 150 159\n163 178 188\n170 185 194\n178 193 201\n"...

Expected Output: 70 85 95 80 95 105 90 105 115 117 130 140 127 140 149 137 150 159 163 178 188 170 185 194 178 193 201 Actual Output: 6 21 31 37 9 19 26 41 51 31 2 12 12 26 7 8 22 31 34 49 59 42 14 23 49 0 9 :( blur correctly filters 4x4 image Cause expected "70 85 95\n80 9...", not "6 21 31\n37 9 ..."

Log testing with sample 4x4 image first row: (10, 20, 30), (40, 50, 60), (70, 80, 90), (100, 110, 120) second row: (110, 130, 140), (120, 140, 150), (130, 150, 160), (140, 160, 170) third row: (195, 204, 213), (205, 214, 223), (225, 234, 243), (245, 254, 253) fourth row: (50, 28, 90), (0, 0, 0), (255, 255, 255), (85, 85, 85) running ./testing 3 4... checking for output "70 85 95\n80 95 105\n100 115 125\n110 125 135\n113 126 136\n123 136 145\n142 155 163\n152 165 173\n113 119 136\n143 151 164\n156 166 171\n180 190 194\n113 112 132\n155 156 171\n169 174 177\n203 207 209\n"...

Expected Output: 70 85 95 80 95 105 100 115 125 110 125 135 113 126 136 123 136 145 142 155 163 152 165 173 113 119 136 143 151 164 156 166 171 180 190 194 113 112 132 155 156 171 169 174 177 203 207 209 Actual Output: 6 21 31 37 9 19 14 29 39 46 61 7 28 41 8 9 22 3 27 12 21 23 36 2 28 34 8 1 8 21 13 23 0 9 19 23 48 47 3 27 27 0 41 3 5 10 15 17

2
  • We are not interested in what chatGPT says. chatGPT is garbage.. the duck and chatGPT can not say your code is correct. they can say it matches someone elses bad code.
    – UpAndAdam
    Nov 3, 2023 at 13:39
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Nov 7, 2023 at 20:53

1 Answer 1

1

i would suggest you trimming your demonstration output down to a single color and making a minimal example of the output we dont need to know every case where you failed.. just a short simple one that demonstrates the problem.

A single 3 by 3 image window would be enough to demonstrate your problem. if you cant get that right, nothing else will be right.

Think in subproblems. You did that in a good way with creating your average sub function.

Update removed incorrect statements I had made after double checking the problem.

Your problem is that you are doing everything with integers which is incorrect. You need to cast the result of your summation to a double, then divide by a double-casted version of your denominator, then that result should be rounded to an int with the round function.

i.e. to demonstrate a single color

avg.rgbtRed = (int) round((double)avg.rgbtRed / (double)n);
0

You must log in to answer this question.

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