0

the output of my program seems fine. When i run Check50 though i get two error messages:

:( edges correctly filters 3x3 image expected "76 117 255\n21...", not "76 117 255\n21..."

:( edges correctly filters 4x4 image expected "76 117 255\n21...", not "76 117 255\n21..."

I'd be grateful for any advice :)

// Detect edges
void edges(int height, int width, RGBTRIPLE image[height][width])
{
    //first a 1-pixel, black frame is added 
    RGBTRIPLE temp [height + 2][width + 2];

    for (int i = 0; i < height + 1; i++)
    {
        temp[i][0].rgbtBlue = 0;
        temp[i][0].rgbtGreen = 0;
        temp[i][0].rgbtRed = 0;

        temp[i][width + 1].rgbtBlue = 0;
        temp[i][width + 1].rgbtGreen = 0;
        temp[i][width + 1].rgbtRed = 0;


        for (int j = 0; j < width + 1; j++)
        {
            temp[i + 1][j + 1] = image[i][j];
        }
    }
    for (int i = 0; i < width +1; i++)
    {
        temp[0][i].rgbtBlue = 0;
        temp[0][i].rgbtGreen = 0;
        temp[0][i].rgbtRed = 0;

        temp[height + 1][i].rgbtBlue = 0;
        temp[height + 1][i].rgbtGreen = 0;
        temp[height + 1][i].rgbtRed = 0;
    }

    //copy of temp is made (temp2)
    RGBTRIPLE temp2[height + 2][width + 2];

    for (int i = 0; i < height + 2; i++)
    {
        for (int j = 0; j < width + 2; j++)
        {
            temp2[i][j] = temp[i][j];
        }
    }


    for (int i = 1; i < height + 1; i++)
    {
        for(int j = 1; j < width + 1; j++)
        {
        //G(x) rot
        int numRx = (temp2[i - 1][j - 1].rgbtRed * -1) + (temp2[i - 1][j + 1].rgbtRed * 1) + (temp2[i][j - 1].rgbtRed * -2) + (temp2[i][j + 1].rgbtRed * 2) + (temp2[i + 1][j - 1].rgbtRed * -1) + (temp2[i + 1][j + 1].rgbtRed * 1);
        //G(y) rot
        int numRy = (temp2[i - 1][j - 1].rgbtRed * -1) + (temp2[i - 1][j].rgbtRed * - 2) + (temp2[i - 1][j + 1].rgbtRed * - 1) + (temp2[i + 1][j - 1].rgbtRed * 1) + (temp2[i + 1][j].rgbtRed * 2) +  (temp2[i + 1][j + 1].rgbtRed * 1);
        int numR = round(sqrt(pow(numRx, 2) + pow(numRy, 2)));
        temp[i][j].rgbtRed = min(numR, 255);
        image[i - 1][j - 1].rgbtRed = temp[i][j].rgbtRed;

        //G(x) blau
        int numBx = (temp2[i - 1][j - 1].rgbtBlue * -1) + (temp2[i - 1][j + 1].rgbtBlue * 1) + (temp2[i][j - 1].rgbtBlue * -2) + (temp2[i][j + 1].rgbtBlue * 2) + (temp2[i + 1][j - 1].rgbtBlue * -1) + (temp2[i + 1][j + 1].rgbtBlue * 1);
        //G(y) blau
        int numBy = (temp2[i - 1][j - 1].rgbtBlue * -1) + (temp2[i - 1][j].rgbtBlue * - 2) + (temp2[i - 1][j + 1].rgbtBlue * - 1) + (temp2[i + 1][j - 1].rgbtBlue * 1) + (temp2[i + 1][j].rgbtBlue * 2) +  (temp2[i + 1][j + 1].rgbtBlue * 1);
        int numB = round(sqrt(pow(numBx, 2) + pow(numBy, 2)));
        temp[i][j].rgbtBlue = min(numB, 255);
        image[i - 1][j - 1].rgbtBlue = temp[i][j].rgbtBlue;

        //G(x) grün
        int numGx = (temp2[i - 1][j - 1].rgbtGreen * -1) + (temp2[i - 1][j + 1].rgbtGreen * 1) + (temp2[i][j - 1].rgbtGreen * -2) + (temp2[i][j + 1].rgbtGreen * 2) + (temp2[i + 1][j - 1].rgbtGreen * -1) + (temp2[i + 1][j + 1].rgbtGreen * 1);
        //G(y) grün
        int numGy = (temp2[i - 1][j - 1].rgbtGreen * -1) + (temp2[i - 1][j].rgbtGreen * - 2) + (temp2[i - 1][j + 1].rgbtGreen * - 1) + (temp2[i + 1][j - 1].rgbtGreen * 1) + (temp2[i + 1][j].rgbtGreen * 2) +  (temp2[i + 1][j + 1].rgbtGreen * 1);
        int numG = round(sqrt(pow(numGx, 2) + pow(numGy, 2)));
        temp[i][j].rgbtGreen = min(numG, 255);
        image[i - 1][j - 1].rgbtGreen = temp[i][j].rgbtGreen;

        }
    }

    return;
}

int min (int x, int y)
{
    if (x > y)
    {
        return y;
    }
    else
    {
        return x;
    }
}
0

When filling up with zeroes in the first for loop, you don't get to fill the last one. Should be for (int i = 0; i < height + 2; i++). It should work with that.

1

You must log in to answer this question.

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