0

Struggling with making the blur filter function for filter(less comfortable):

When i try to run the program with the input and output file i get the errors marked by the asterisk (*) on line 26,27,28. It's the same error for all the images i tried. Been struggling to find the reason, cause the rest program runs ok except for those 3 lines....

Link to code:

https://gist.github.com/suenolivia/83b2f7a8fcf445a3cecb2431d9c2a8d1#file-pset4_filter_less-L26

Any help is appreciated thanks!!!

1

I realised that in line 4 i am assigning values to float only once. So when I loop it in the following lines, avg_of_9_blue, avg_of_9_red and avg_of_9_green just keep increasing past 255. Corrected this an place the assignment of float values into the if statement.

Afterwards, realised that i am changing all the original RBGT values when assigning new values to the original RGBT values, hence subsequent "boxes" rgbt values will be calculated using this new values(which is wrong). Hence, proceeded to create a RGBTRIPLE temp[height][width] to store the new values(while keeping the original). At the end creating a new loop to update all image[height][width] values to the new ones to blur the image.

| improve this answer | |
0

The values of image[i][j].rgbtBlue, image[i][j].rgbtRed and image[i][j].rgbtGreen are stored as what CS50 defined as a BYTE, which is actually an unsigned integer of length 8 bits. The maximum value for this data type is 255.

In the lines with the errors, you are trying to assign values outside of this range (i.e. 285, 328 and 309) to image[i][j].rgbtBlue, image[i][j].rgbtRed and image[i][j].rgbtGreen, causing this error.

I suggest using debug50 to step through this process and taking a look at each variable before this to see why you're getting values above 255 (you shouldn't be!)


Another problem with you program is that you're changing the original image array as you're going along. While your end result will indeed be a blurred version of the original image, it'll not be what check50 expects!

Hope this helps and do mark this as an answer if it does!

| improve this answer | |
  • Thanks for your reply, i actually realised that i made a careless mistake. And thanks for pointing out the 2nd problem realised that as well. – Olivia May 10 at 13:40

You must log in to answer this question.

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