#need help with a cs50 problem

1 messages · Page 1 of 1 (latest)

ashen belfry
#

Share the problem, share the code, etc. Read the #📄・posting-guidelines and adjust your post

dark tusk
#

Post it here and I shall take a look

gritty lion
dark tusk
#

#☕・hangout message called it 🗣️

#

no wait you're implementing some sort of image blur?

gritty lion
dark tusk
#

not the jpeg recovery I'm st00pid

gritty lion
#

youre good bro

dark tusk
#

So you have some sort of bitmap image and want to apply a blur filter?

gritty lion
#

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

dark tusk
#

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?

gritty lion
#

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

dark tusk
#

Haha I was about to say that my guess is overflowing chars

gritty lion
#

well you may be right but i have no clue on how to fix it

dark tusk
#

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)

gritty lion
#

oh man that might actually be it.

dark tusk
#

That looks fishy to me, could be that you're just forgetting about the last surrounding value in some cases

gritty lion
#

if so how embarrassing

dark tusk
#

Produced at least two of those today kek

gritty lion
#

well it actually got two of the check 50 working

dark tusk
#

So something is still off in there

gritty lion
#

yeah but thanks for the catch still

#

ill check and see rq if there is something wrong

dark tusk
#

Just to confirm, RGBTRIPLE is a struct containing 3 char (1 byte) values?

gritty lion
#

oh sorry no its an int

dark tusk
#

Okay, so we're not gonna overflow there

#

What did you change the loo pcondition to?

gritty lion
#

no actually its a byte

#

sorry

dark tusk
#

Yeah, then that might explain the issue

gritty lion
dark tusk
#

the for loop in line 167

#

should either be m < 9 or m <= 8

gritty lion
#

yeah i did 9

dark tusk
#

(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

gritty lion
#

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

dark tusk
#

So avrg has three ints?

gritty lion
#

yes

#

and so does srnd

dark tusk
#

Oh it's just a rounding issue now

#

You're getting 126, they expect 127

gritty lion
#

could be but heres something i dont understand

#

it says it needs 70 85 95 and then it says i have those numbers

dark tusk
#

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?

gritty lion
#

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

dark tusk
#

Let's try fixing the rounding first, we can check if the other thing goes away after

gritty lion
#

alr how would i do that

dark tusk
#

Do they tell you how to round the values? Seems like you're just rounding down, maybe they expect you to always round up?

gritty lion
#

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

dark tusk
#

Rounding to the nearest integer can have multiple meanings 🗣️

#

But yeah, I'd ask on their server what exactly they mean

gritty lion
#

ok ill do that. thanks again man

#

turns out im a fool and decided that id make sum an int instead of a float. its working now so im gonna delete this thread but you were a huge help