0
:( sepia correctly filters simple 3x3 image
    expected "100 89 69\n100...", not "100 89 69\n100..."
:( 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..."

I don't know why i keep getting wrong outcome on check50, even though it seems like the numbers i get are correct.

void sepia(int height, int width, RGBTRIPLE image[height][width])
{
    for (int i = 0; i <= height; i++)
    {
        for (int j = 0; j <= width; j++)
        {
            float r = round((image[i][j].rgbtRed * 0.393) + (image[i][j].rgbtGreen * 0.769) + (image[i][j].rgbtBlue * 0.189));
            float g = round((image[i][j].rgbtRed * 0.349) + (image[i][j].rgbtGreen * 0.686) + (image[i][j].rgbtBlue * 0.168));
            float b = round((image[i][j].rgbtRed * 0.272) + (image[i][j].rgbtGreen * 0.534) + (image[i][j].rgbtBlue * 0.131));
            if (r > 255)
                image[i][j].rgbtRed = 255;
            if (g > 255)
                image[i][j].rgbtGreen = 255;
            if (b > 255)
                image[i][j].rgbtBlue = 255;
            image[i][j].rgbtRed = (int)r;
            image[i][j].rgbtGreen = (int)g;
            image[i][j].rgbtBlue = (int)b;
        }
    }
    return;
}
0

Your error takes place when you assign r, b, and g to the image. Whenever r, b, or g is greater than 255, it assigns 255 to that pixel and then assigns the higher value. The solution is to use if-else statements in place of if statements. For example:

if (b > 255)
    image[i][j].rgbtBlue = 255;
image[i][j].rgbtBlue = (int)b;

becomes

if (b > 255)
    image[i][j].rgbtBlue = 255;
else
    image[i][j].rgbtBlue = (int)b;

I would also suggest that you use curly braces with the if-else statements even though they are one-liners.

Hope this helps. If it does then please check the tickmark.

2
  • The outcome is still the same, i guess i'll just skip it at this point. – cheero Apr 3 at 3:18
  • nvm, solved it buy changing i <= height / j <= width to < – cheero Apr 3 at 8:52

You must log in to answer this question.

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