0

I have been staring at Edges for a whole day, still can't find out what's wrong with it. The test says the middle pixel is correctly calculated. but edges, corners, 3X3....no go. Anybody can offer a second pair of eyes? Here is the code:

void edges(int height, int width, RGBTRIPLE image[height][width]) { //placeholder image RGBTRIPLE Outimg[height][width];

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


//Go through each pixel of the original image
for (int i=0; i<height; i++)
{

    for (int j=0; j<width; j++)
        {   //initialize the gx, gy for the RBG of each pixel
            int gx_b = 0;
            int gy_b = 0;
            int gx_r = 0;
            int gy_r = 0;
            int gx_g = 0;
            int gy_g = 0;

            //iterate over a grid of 3x3
            for (int h=0; h<3; h++)
                {
                    for (int m=0; m<3; m++)
                    {   if(i+h-1<0 ||i+h-1>height-1 || j+m-1<0 || j+m-1>width-1)
                            {
                                image[i+h-1][j+m-1].rgbtBlue=0;
                                image[i+h-1][j+m-1].rgbtRed=0;
                                image[i+h-1][j+m-1].rgbtGreen=0;
                            }


                        gx_b += Gx[h][m]*image[i+h-1][j+m-1].rgbtBlue;
                        gx_r += Gx[h][m]*image[i+h-1][j+m-1].rgbtRed;
                        gx_g += Gx[h][m]*image[i+h-1][j+m-1].rgbtGreen;
                        gy_b += Gy[h][m]*image[i+h-1][j+m-1].rgbtBlue;
                        gy_r += Gy[h][m]*image[i+h-1][j+m-1].rgbtRed;
                        gy_g += Gy[h][m]*image[i+h-1][j+m-1].rgbtGreen;


                    }
                }

                         Outimg[i][j].rgbtBlue = sqrt(gx_b*gx_b + gy_b*gy_b));
                         Outimg[i][j].rgbtRed = sqrt(gx_r*gx_r + gy_r*gy_r));
                         Outimg[i][j].rgbtGreen = sqrt(gx_g*gx_g + gy_g*gy_g));

                           if (Outimg[i][j].rgbtBlue>255)
                            {Outimg[i][j].rgbtBlue=255;};
                             if (Outimg[i][j].rgbtRed>255)
                            {Outimg[i][j].rgbtRed=255;};
                            if (Outimg[i][j].rgbtGreen>255)
                            {Outimg[i][j].rgbtGreen=255;};
        }
}

 for (int i=0; i<height; i++)
{
    for (int j=0; j<width; j++)
    {
        image[i][j] = Outimg[i][j];
    }
}
return;

}

Thanks a lot in advance! Best,emphasized text

You must log in to answer this question.

Browse other questions tagged .