0

So, I currently have this solution for the sepia function of the filter problem.

void sepia(int height, int width, RGBTRIPLE image[height][width])
{
    int b, g, r;

    // Apply sepia algorithm to each pixel
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            b = round(0.272 * image[i][j].rgbtRed
                      + 0.534 * image[i][j].rgbtGreen
                      + 0.131 * image[i][j].rgbtBlue);

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

            g = round(0.349 * image[i][j].rgbtRed
                      + 0.686 * image[i][j].rgbtGreen
                      + 0.168 * image[i][j].rgbtBlue);

            if (g > 255) image[i][j].rgbtGreen = 255;
            else image[i][j].rgbtGreen = g;

            r = round(0.393 * image[i][j].rgbtRed
                      + 0.769 * image[i][j].rgbtGreen
                      + 0.189 * image[i][j].rgbtBlue);

            if (r > 255) image[i][j].rgbtRed = 255;
            else image[i][j].rgbtRed = r;
        }
    }
}

As far as I can tell, this should work, but only the red (or blue, I don't know what order check50 prints the values in) is correct, while the others are consistently way off.

I've checked the values used in the algorithms and I don't see the issue? It's definitely not a rounding error either - the values are multiple integers off.

1 Answer 1

1

You are changing the values of the blue component of the pixel before you use it to calculate the green and red; you are changing the value of the green pixel before you are using it to calculate the red.

Make sure that you use the original pixel components in all 3 of the color calculations.

You must log in to answer this question.

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