0
    //Pixel buffer
    RGBTRIPLE pixelBuffer[height][width];

    //Iterates on every pixel and calculates Gx and Gy
    for (int i = 0; i < height; i++)
    {
        for (int j = 0; j < width; j++)
        {
            if (j > 0 && j < width - 1 && i > 0 && i < height - 1)
            {
                //Calculates Gx
                int blueGx = round((float)(image[i][j].rgbtBlue * 0 + image[i][j + 1].rgbtBlue * 2 + image[i][j - 1].rgbtBlue * -2 +
                                                image[i + 1][j].rgbtBlue * 0 + image[i + 1][j + 1].rgbtBlue * 1 + image[i + 1][j - 1].rgbtBlue * -1 +
                                                image[i - 1][j].rgbtBlue * 0 + image[i - 1][j + 1].rgbtBlue * 1 + image[i - 1][j - 1].rgbtBlue * -1));

                int greenGx = round((float)(image[i][j].rgbtGreen * 0 + image[i][j + 1].rgbtGreen * 2 + image[i][j - 1].rgbtGreen * -2 +
                                                image[i + 1][j].rgbtGreen * 0 + image[i + 1][j + 1].rgbtGreen * 1 + image[i + 1][j - 1].rgbtGreen * -1 +
                                                image[i - 1][j].rgbtGreen * 0 + image[i - 1][j + 1].rgbtGreen * 1 + image[i - 1][j - 1].rgbtGreen * -1));

                int redGx = round((float)(image[i][j].rgbtRed * 0 + image[i][j + 1].rgbtRed * 2 + image[i][j - 1].rgbtRed * -2 +
                                                image[i + 1][j].rgbtRed * 0 + image[i + 1][j + 1].rgbtRed * 1 + image[i + 1][j - 1].rgbtRed * -1 +
                                                image[i - 1][j].rgbtRed * 0 + image[i - 1][j + 1].rgbtRed * 1 + image[i - 1][j - 1].rgbtRed * -1));


                //Calculates Gy
                int blueGy = round((float)(image[i][j].rgbtBlue * 0 + image[i][j + 1].rgbtBlue * 0 + image[i][j - 1].rgbtBlue * 0 +
                                                image[i + 1][j].rgbtBlue * 2 + image[i + 1][j + 1].rgbtBlue * 1 + image[i + 1][j - 1].rgbtBlue * 1 +
                                                image[i - 1][j].rgbtBlue * -2 + image[i - 1][j + 1].rgbtBlue * -1 + image[i - 1][j - 1].rgbtBlue * -1));

                int greenGy = round((float)(image[i][j].rgbtGreen * 0 + image[i][j + 1].rgbtGreen * 0 + image[i][j - 1].rgbtGreen * 0 +
                                                image[i + 1][j].rgbtGreen * 2 + image[i + 1][j + 1].rgbtGreen * 1 + image[i + 1][j - 1].rgbtGreen * 1 +
                                                image[i - 1][j].rgbtGreen * -2 + image[i - 1][j + 1].rgbtGreen * -1 + image[i - 1][j - 1].rgbtGreen * -1));

                int redGy = round((float)(image[i][j].rgbtRed * 0 + image[i][j + 1].rgbtRed * 0 + image[i][j - 1].rgbtRed * 0 +
                                                image[i + 1][j].rgbtRed * 2 + image[i + 1][j + 1].rgbtRed * 1 + image[i + 1][j - 1].rgbtRed * 1 +
                                                image[i - 1][j].rgbtRed * -2 + image[i - 1][j + 1].rgbtRed * -1 + image[i - 1][j - 1].rgbtRed * -1));



                //Adds the averaged value to the buffer 2d array
                pixelBuffer[i][j].rgbtBlue = sqrt(blueGx * blueGx + blueGy * blueGy);
                pixelBuffer[i][j].rgbtGreen = sqrt(greenGx * greenGx + greenGy * greenGy);
                pixelBuffer[i][j].rgbtRed = sqrt(redGx * redGx + redGy * redGy);
            }

It's pretty hardcoded but is my logic wrong here. I'm not calculating for the borders here so ignore that.

Check50 outputs values are way different than mine except for green pixel I think, but the image seems kind of correct.

https://imgur.com/a/0ClIACW

0

That's the correct image: https://imgur.com/a/Z4APwpb It seems that something is wrong with the edges for sure. And also something wrong with the rest of the numbers, too, because I see a lot of noise in your image (compare the left chimney, for instance).

It would be great if you can figure out a less hard-coded version. Less hard coded versions protect us from typing mistakes, and make the code clearer to read and easier to debug. A paper and pen helps a lot, think in increments, small steps. Also remember the specification, the values need to be capped at 255!!! The gradient magnitude, i.e. the square root of the summed squares, for each color can be higher than 255 while it shouldn't.

You must log in to answer this question.

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