0

the rightmost values in the matrix in check50 is wrong but the other values are correct. I'm not really sure what's wrong. code:

void edges(int height, int width, RGBTRIPLE image[height][width])
{
float sum_redgx, sum_greengx, sum_bluegx, sum_redgy, sum_greengy, sum_bluegy;
//temp image for storing values
RGBTRIPLE temp_img[height][width];


for (int i = 0; i < height; i++)
{
    for (int j = 0; j < width; j++)
    {
        sum_redgx = 0;
        sum_bluegx = 0;
        sum_greengx = 0;
        sum_redgy = 0;
        sum_bluegy = 0;
        sum_greengy = 0;
        
        for (int a = 0; a < 3; a++)
        {
            int iterate_i = i + blur[a];
            
            if (iterate_i < 0 || iterate_i > height - 1)
            {
                continue;
            }
            
            for (int b = 0; b < 3; b++)
            {
                int iterate_j = j + blur[b];
                if (iterate_j < 0 || iterate_j > width - 1)
                {
                    continue;
                }
                
                sum_redgx += image[iterate_i][iterate_j].rgbtRed * Gx[a][b];
                sum_greengx += image[iterate_i][iterate_j].rgbtGreen * Gx[a][b];
                sum_bluegx += image[iterate_i][iterate_j].rgbtBlue * Gx[a][b];
                sum_redgy += image[iterate_i][iterate_j].rgbtRed * Gy[a][b];
                sum_greengy += image[iterate_i][iterate_j].rgbtGreen * Gy[a][b];
                sum_bluegy += image[iterate_i][iterate_j].rgbtGreen * Gx[a][b];
            }
            
            temp_img[i][j].rgbtRed = check(round(sqrt((sum_redgx * sum_redgx) + (sum_redgy * sum_redgy))));
            temp_img[i][j].rgbtGreen = check(round(sqrt((sum_greengx * sum_greengx) + (sum_greengy * sum_greengy))));
            temp_img[i][j].rgbtBlue = check(round(sqrt((sum_bluegx * sum_bluegx) + (sum_bluegy * sum_bluegy))));
        }
    }
}

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

I'm going to guess your check() function caps the value to 255 max. However, you store the value in your temp_img before capping it, and the RGBTRIPLE type is made up of unsigned chars which cannot hold a value over 255; consequently the values will get wrapped to incorrect ones.

Apply the check() function to the rounded value you calculate.

3
  • did that but still the same error – Gloria Isedu Nov 27 '20 at 21:38
  • 1
    In the last (6th) line when adding to your pixel sum for bluegy, you use rgbtGreen instead of rgbtBlue, and Gx instead of Gy. – Sentox Nov 28 '20 at 0:09
  • thank you, it worked. – Gloria Isedu Nov 28 '20 at 16:50

You must log in to answer this question.

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