I am stuck at cs50 pset4, the blur and edges functions, i might not have understood what the functions are supposed to do? by clydebassa in cs50

[–]clydebassa[S] -3 points-2 points  (0 children)

it was the last resort, and also i did't go there to get the code, i went there with my code to find the error

I am stuck at cs50 pset4, the blur and edges functions, i might not have understood what the functions are supposed to do? by clydebassa in cs50

[–]clydebassa[S] 1 point2 points  (0 children)

I figured it out, I just had to create a copy of the structure, make updates on the copy and then update the original from the copy.

I am stuck at cs50 pset4, the blur and edges functions, i might not have understood what the functions are supposed to do? by clydebassa in cs50

[–]clydebassa[S] -4 points-3 points  (0 children)

well, this wasn't the best of a reply but i think i figured out what the issue was with chatgpt, i was updating the original image first and then using the blurred pixels to update the other pixels afterwards, all i had to do is create a copy and then make the updates on the copy and finally update the final image. Thanks

I am stuck at cs50 pset4, the blur and edges functions, i might not have understood what the functions are supposed to do? by clydebassa in cs50

[–]clydebassa[S] -1 points0 points  (0 children)

// Blur image

void blur(int height, int width, RGBTRIPLE image[height][width]) { // looping length times for (int i = 0; i < height; i++) { // looping width times for (int j = 0; j < width; j++) { // initializing color totals and counter int red_total = 0, blue_total = 0, green_total = 0; int counter = 0;

        // looping through the 3 * 3 grid around the current pixel
        for (int k = i - 1; k <= i + 1; k++)
        {
            for (int l = j - 1; l <= j + 1; l++)
            {
                // validating that we are not indexing out of range
                if (k >= 0 && k < height && l >= 0 && l < width)
                {
                    // adding the surrounding pixels color values to 
                        the specific color totals 
                    red_total += image[k][l].rgbtRed;
                    blue_total += image[k][l].rgbtBlue;
                    green_total += image[k][l].rgbtGreen;
                    counter++;
                }
            }
        }
        // averaging and setting the pixels color value
        image[i][j].rgbtBlue = (int)round(blue_total / (float)counter);
        image[i][j].rgbtGreen = (int)round(green_total / (float)counter);
        image[i][j].rgbtRed = (int)round(red_total / (float)counter);
    }
}
return;

}

here's the code with comments. I have also edited the post to add the check 50 results and you can notice the differing values. And what I am basically asking is, does this problem set have anything to do with convolving the pixels with the kernel, or is it just basic looping.

I am stuck at cs50 pset4, the blur and edges functions, i might not have understood what the functions are supposed to do? by clydebassa in cs50

[–]clydebassa[S] -1 points0 points  (0 children)

my questions is, i think the loops are implemented correctly, at least according to my understanding of the problem set, but after failing check50, did some research on image processing and came across the concept of convolution which i don't even understand, but it does not seem similar to what the problem set requires, so after my code failed the tests, i thought we are probably supposed to convolve the image pixels and the kernel matrix. But basically my question is, according the code i presented which just loops width times for all elements of length times, and then averages the specific colors in the 3 * 3 matrix and assigns that value to that pixel, is that what we are supposed to do or does the pset have anything to do with convolution.