0
int cap (int value)
{
    return value < 255 ? value: 255;
}


RGBTRIPLE get_edge(int i, int j, int height, int width, RGBTRIPLE image[height][width])
{
    int Gx[3][3] = {{ -1, 0, 1}, {-2, 0, 2}, { -1, 0, 1}};
    int redvalueX = bluevalueX = greenvalueX = redvalueY = bluevalueY = greenvalueY = 0;

    for(int di = -1; di <= 1; di++)
    {

         for(int dj = -1; dj <= 1; dj++)
         {
             if (isvalid(i + di, i + dj, height, width))
             {
                 int weightX = Gx[di + 1][dj + 1];
                 redvalueX += weightX * image[i + di][j + dj].rgbtRed;
                 bluevalueX += weightX * image[i + di][j + dj].rgbtBlue;
                 greenvalueX += weightX * image[i + di][j + dj].rgbtGreen;

                 int weightY = Gx[dj + 1][di + 1];
                 redvalueY += weightY * image[i + di][j + dj].rgbtRed;
                 bluevalueY += weightY * image[i + di][j + dj].rgbtBlue;
                 greenvalueY += weightY * image[i + di][j + dj].rgbtGreen;
             }
         }

    }
    RGBTRIPLE pixel;
    pixel.rgbtRed = cap(round(sqrt(redvalueX * redvalueX + redvalueY * redvalueY)));
    pixel.rgbtBlue = cap(round(sqrt(bluevalueX * bluevalueX + bluevalueY * bluevalueY)));
    pixel.rgbtGreen = cap(round(sqrt(greenvalueX * greenvalueX  + greenvalueY * greenvalueY)));
    return pixel;
}

void edges(int height, int width, RGBTRIPLE image[height][width])
{
    RGBTRIPLE newImage[height][width];
        for(int i = 0; i < height; i++)
    {
        for( int j = 0; j < width; j++)
        {
           newImage[i][j] = get_edge(i, j, height, width, image);
        }
    }
    for (int i = 0; i < height; i++)
        for (int j = 0; j < width; j++)
            image[i][j] = newImage[i][j];

}

You must log in to answer this question.

Browse other questions tagged .