#need help with a cs50 problem
1 messages · Page 1 of 1 (latest)
Post it here and I shall take a look
oh wow thats funny. i wasnt sure what you meant bc i was working with bitmaps. idk how i didnt connect the dots
not the jpeg recovery I'm st00pid
youre good bro
So you have some sort of bitmap image and want to apply a blur filter?
yeah and the way to do it is gather all of the surrounding pixels and get an average of the rgb values and put them in the current pixel
Sounds reasonable so far
What does the RGBTRIPLE struct look like? And what's the type of the srnd array?
I assume sum is the count of surrounding pixels you're averaging for the current pixel?
so the rgbtriple struct has three bytes for red green and blue and i made my own struct that has ints so when i add and then divide by sum it doesnt overflow i originally had srnd and avrg as rgbtriple until someone in the cs50 server said it could be overflow
yep
Haha I was about to say that my guess is overflowing chars
well you may be right but i have no clue on how to fix it
Change it to use ints instead of chars? Or keep some temporary variable
I think your loop may be off by one as well
Since you fill up the srnd array on indices 0 through 8 (3x3 area), but your loop in line 167 stops at index 7 (m < 8)
oh man that might actually be it.
That looks fishy to me, could be that you're just forgetting about the last surrounding value in some cases
if so how embarrassing
lol off by ones are like the single most common bug in programming
Produced at least two of those today kek
well it actually got two of the check 50 working
So something is still off in there
yeah but thanks for the catch still
ill check and see rq if there is something wrong
Just to confirm, RGBTRIPLE is a struct containing 3 char (1 byte) values?
oh sorry no its an int
Yeah, then that might explain the issue
wdym
yeah i did 9
You're adding 9 values (index 0-8) of 1 byte each into a variable that's also 1 byte you might be overflowing that variable
(it wraps around and we get a wrong result in the end)
Simple solution would be to introduce 3 new variables of a larger size (e.g. int should be more than enough) above the loop, then we add into those variables, divide them by the count and store them back into the npxl
well for avrg and srnd im using my own struct that they didnt make called rgbtriple int with three ints instead of the rgbtriple with three bytes
So avrg has three ints?
could be but heres something i dont understand
it says it needs 70 85 95 and then it says i have those numbers
Yeah that looks weird 💀
No idea how their test runner works, could it be that they're truncating the output when the issue is in the pixel after?
yeah truthfully i couldnt even guess ill probably just hand it over to people in the cs50 server. youve already helped out a bunch so thanks man i appreciate it
Let's try fixing the rounding first, we can check if the other thing goes away after
alr how would i do that
Do they tell you how to round the values? Seems like you're just rounding down, maybe they expect you to always round up?
i think they just said round. i included a header file math.h and its from a cs50 manual website. its one of the functions on thier website
yeah i just checked the video it said rounded to the nearest integer
i also just checked that function on the website it says it rounds to the nearest integer