0

I am trying to code Pset4 (more comfortable) edges, the program is running, but my outcome is completely white. Any Suggestions? Here's My Code....

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

{
RGBTRIPLE out[height][width];

// Making A Copy Of Image

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

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

// Going Through The Image
for (int i = 0; i < height; i++)
{   
    // Declaring x,y components

    long rx = 0, ry = 0;
    long gx = 0, gy = 0;
    long bx = 0, by = 0;

    for (int j = 0; j < width; j++)
    {
        // Going Through Gx and Gy Matrix

        for (int m = 0; m < 3; m++)
        {
            for (int n = 0; n < 3; n++)
            {
                if (i-1+m < 0 || i-1+m > height - 1 || j-1+n < 0 || j-1+n > width - 1 )
                {
                    continue;
                }
                rx += image[i-1+m][j-1+n].rgbtRed * Gx[m][n];
                ry += image[i-1+m][j-1+n].rgbtRed * Gy[m][n];
                bx += image[i-1+m][j-1+n].rgbtBlue * Gx[m][n];
                by += image[i-1+m][j-1+n].rgbtBlue * Gy[m][n];
                gx += image[i-1+m][j-1+n].rgbtGreen * Gx[m][n];
                gy += image[i-1+m][j-1+n].rgbtGreen * Gy[m][n];
            }
        }

         int red = round( fmin(255,sqrt((rx*rx) + (ry*ry))) );
         int blue = round( fmin(255,sqrt((bx*bx) + (by*by))) );
         int green = round( fmin(255,sqrt((gx*gx) + (gy*gy))) );



        // Setting Value In Image

       image[i][j].rgbtRed = red;
       image[i][j].rgbtGreen = green;
       image[i][j].rgbtBlue = blue;

    }
}


return;

}

1

I've found 3 problems in your code: 1. You're making a copy of the image but you're not using it? 2. Revise the arrays Gx-Gy something is wrong. 3. Pay attention where you declare the group of long variables rx-ry-gx-gy-etc.

1
  • Thank You. I was just about to give up. I fixed the third and the first problem last night. But was completely ignorant about the rest. Thanks for the help. – Paarth Rawat Apr 15 '20 at 8:24
0

as for the second problem check the last row of your Gx. there needs to be 0 in the middle not 2

You must log in to answer this question.

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