1

My code is here.

    void sepia(int height, int width, RGBTRIPLE image[height][width])
{   for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            int newred = round(.393*image[i][j].rgbtRed + .769*image[i][j].rgbtGreen + .189*image[i][j].rgbtBlue);
            if(newred>255)
            {
                newred = 255;
            }
            image[i][j].rgbtRed = newred;

            int newgreen = round(.349*image[i][j].rgbtRed + .686*image[i][j].rgbtGreen + .168*image[i][j].rgbtBlue);
            if(newgreen>255)
            {
                newgreen = 255;
            }
            image[i][j].rgbtGreen = newgreen;

            int newblue = round(.272*image[i][j].rgbtRed + .534*image[i][j].rgbtGreen + .131*image[i][j].rgbtBlue);
            if(newblue>255)
            {
                newblue = 255;
            }
            image[i][j].rgbtBlue = newblue;
        }
    }
    return;
}

The results are as follows

:( sepia correctly filters single pixel
    expected "56 50 39\n", not "56 62 60\n"
:( sepia correctly filters simple 3x3 image
    expected "100 89 69\n100...", not "100 35 46\n100..."
:( sepia correctly filters more complex 3x3 image
    expected "25 22 17\n66 5...", not "25 27 25\n66 6..."
:( sepia correctly filters 4x4 image
    expected "25 22 17\n66 5...", not "25 27 25\n66 6..."

I don't understand why its wrong because my logic seems fine

1

Remember,

Not Everytime multiplying a point notation will yield a perfect integer, so directly assigning a point notation to the single channel of a pixel won't work.

You have to store the value in a float and then round it off and store it in an integer.

float new_value = (formula);
int new_channel = round(new_value);
image[i][j].rgbt = new_channel;
| improve this answer | |

You must log in to answer this question.

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