CS50 blur function does not pass check50, even though image is being blurred

前端 未结 1 1218
失恋的感觉
失恋的感觉 2021-01-21 18:30

I am working on a CS50 problem set in which I need to do a box blur for each pixel of an image. Though my code is a bit redundant, as I had created 8 if statements for special c

相关标签:
1条回答
  • 2021-01-21 19:11

    You are modifying your image as you apply blur function to the pixels. This means when you modify few pixels, the adjacent pixels blur values are calculated with "blurred pixel values". This is wrong. All the calculations must be done within original image pixel values. For this, you should create a copy of image in the beginning (such as temp) and make all this calculation within that temp image which has unmodified pixel values.

    Add this to the beginning of your code;

    RGBTRIPLE temp[height][width]; // create a temporary array to store a duplicate of image.
    
    // save a new copy of image as temp per color.
    for (int i = 0; i < height; i++) //Loop for height of image.
    {
        for (int j = 0; j < width; j++) //Loop for width of image and save color values in temp.
        {
            temp[i][j] = image[i][j];
        }
    }
    

    And replace image with temp in your calculations (except the assignment at the end).

    0 讨论(0)
提交回复
热议问题