1

I am having some errors with my code in check50. All of my code is on this gist.

  1. Grayscale - expected "28 28 28\n", not "27 27 27\n" in without whole number average. I am using this
int average = round((image[y][x].rgbtBlue + image[y][x].rgbtGreen + image[y][x].rgbtRed) / 3);

which should be rounding. After this I just assign the values.

  1. Blur - It gives me a wrong value, but I can't identify the bug.
:( blur correctly filters middle pixel
    expected "127 140 149\n", not "128 140 149\n"
  1. I don't know the error in these:
:( blur correctly filters 3x3 image
    expected "70 85 95\n80 9...", not "70 85 95\n80 9..."
:( blur correctly filters 4x4 image
    expected "70 85 95\n80 9...", not "70 85 95\n80 9..."
:( sepia correctly filters more complex 3x3 image
    expected "25 22 17\n66 5...", not "25 22 17\n66 5..."
:( sepia correctly filters 4x4 image
    expected "25 22 17\n66 5...", not "25 22 17\n66 5..."
:( grayscale correctly filters more complex 3x3 image
    expected "20 20 20\n50 5...", not "20 20 20\n50 5..."
:( grayscale correctly filters 4x4 image
    expected "20 20 20\n50 5...", not "20 20 20\n50 5..."
3

Your problem lies with the / operator. Because the RGB values and the denominator are all integers, integer division is being performed and the fractional remainder is dropped instead of being passed to the round function.

Try replacing 3 with 3.0 (which is explicitly a floating point value). When at least one value is a float, floating point math will be performed instead.

0

I found the bug in sepia and in blur and fixed my code. For blur, it turns out that on line 127. I did image2 instead of image resulting in the wrong image. I also forgot to round the values. In sepia I skipped the step to make sure the values aren't over 255.

You must log in to answer this question.

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