0

I've been stuck on the Edge part of Filter (More) for a few days now. Check50 tells me that none of the pixels return the right values but I can't seem to find any problem with the code.

Here's my code:

void edges(int height, int width, RGBTRIPLE image[height][width])

{

          typedef struct

          {

                  float R;

                  float G;

                  float B;

           }

           RGB;

           RGB temp[height + 2][width + 2];

           int GxS[3][3] = {{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}};

           int GyS[3][3] = {{-1, -2, -1}, {0, 0, 0}, {1, 2, 1}};

           for(int a = 0; a < height + 2; a++)

           {

                  for(int b = 0; b < width + 2; b++)

                  {

                            temp[a][b].R = 0;

                            temp[a][b].B = 0;

                            temp[a][b].G = 0;

                    }

            }

            for(int i = 0; i < height; i++)

            {

                    for(int j = 0; j < width; j++)

                    {

                            temp[i + 1][j + 1].R = image[i][j].rgbtRed;

                            temp[i + 1][j + 1].B = image[i][j].rgbtBlue;

                            temp[i + 1][j + 1].G = image[i][j].rgbtGreen;

                     }

             }

             for(int c = 1; c < height + 1; c++)

             {

                     for(int d = 1; d < width + 1; d++)

                     {

                              double GxR = 0;

                              double GxB = 0;

                              double GxG = 0;

                              double GyR = 0;

                              double GyB = 0;

                              double GyG = 0;

                              for(int k = -1; k < 2; k++)

                              {

                                         for(int l = -1; l < 2; l++)

                                         {

                                                   GxR += temp[c + k][d + l].R * GxS[k + 1][l + 1];

                                                   GxB += temp[c + k][d + l].B * GxS[k + 1][l + 1];

                                                   GxG += temp[c + k][d + l].G * GxS[k + 1][l + 1];

                                                   GyR += temp[c + k][d + l].R * GyS[k + 1][l + 1];

                                                   GyB += temp[c + k][d + l].B * GyS[k + 1][l + 1];

                                                   GyG += temp[c + k][d + l].G * GyS[k + 1][l + 1];

                                          }

                                }

                                if(c < height && d < width)

                                 {

                    image[c][d].rgbtRed = (int)round(fmin(sqrt(pow(GxR, 2) + pow(GyR, 2)), 255.0));

                    image[c][d].rgbtBlue = (int)round(fmin(sqrt(pow(GxB, 2) + pow(GyB, 2)), 255.0));

                    image[c][d].rgbtGreen = (int)round(fmin(sqrt(pow(GxG, 2) + pow(GyG, 2)), 255.0));

                                   }

                }

         }

   }

You must log in to answer this question.

Browse other questions tagged .