0
:) edges correctly filters middle pixel

:) edges correctly filters pixel on edge

:) edges correctly filters pixel in corner

:( edges correctly filters 3x3 image

expected "76 117 255\n21...", not "76 117 255\n21..."

    

:( edges correctly filters 4x4 image

  expected "76 117 255\n21...", not "76 117 255\n21..."

Code below:-

void edges(int height, int width, RGBTRIPLE image[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}};
RGBTRIPLE pix[height][width];
    for (int i = 0; i<height; i++ )
    {
        for (int j = 0; j<width; j++)
        {
            float xarR =0;
            float xarB =0;
            float xarG = 0;
            float yarR =0;
            float yarB =0;
            float yarG = 0;
            float SbR =0;
            float SbB =0;
            float SbG = 0;
            for(int squarey = -1; squarey<2; squarey++)
            {
            for(int squarex = -1; squarex<2; squarex++)
                {
                    
            if (j+squarex > width || i+squarey > height || i+squarey < 0 || j+squarex < 0 )
            {
                true;
            }
            else{
                xarR += image[i+squarey][j+squarex].rgbtRed*Gx[squarey+1][squarex+1];
                xarB += image[i+squarey][j+squarex].rgbtBlue*Gx[squarey+1][squarex+1];
                xarG += image[i+squarey][j+squarex].rgbtGreen*Gx[squarey+1][squarex+1];
                yarR += image[i+squarey][j+squarex].rgbtRed*Gy[squarey+1][squarex+1];
                yarB += image[i+squarey][j+squarex].rgbtBlue*Gy[squarey+1][squarex+1];
                yarG += image[i+squarey][j+squarex].rgbtGreen*Gy[squarey+1][squarex+1];
            
            }
            }
            }
            SbR = xarR*xarR + yarR*yarR;
            SbB = xarB*xarB + yarB*yarB;
            SbG = xarG*xarG + yarG*yarG;
            SbG = sqrt(SbG);
            SbB = sqrt(SbB);
            SbR = sqrt(SbR);
            float rounder[3] = {SbR, SbB, SbG};
            for (int roun = 0; roun < 3; roun++)
                {
                    float c = rounder[roun]*10;
                    int b = (int)c;
                    b = b%10;
                    if (b>=5)
                    {
                        rounder[roun]+=1;
                    }
                }
            SbR = rounder[0];
            SbB = rounder[1];
            SbG = rounder[2];
            if (SbG>255)
            {
                SbG = 255;
            }
            if (SbR>255)
            {
                SbR = 255;
            }
            if (SbB>255)
            {
                SbB = 255;
            }
            pix[i][j].rgbtRed = (int)SbR;
            pix[i][j].rgbtBlue = (int)SbB;
            pix[i][j].rgbtGreen = (int)SbG;
        }
    }
    for (int i = 0; i<height; i++ )
    {
        for (int j = 0; j<width; j++)
        {
            image[i][j] = pix[i][j];
        }
    }
    return;
    
}

You must log in to answer this question.

Browse other questions tagged .