I've been working on the Harvard's CS50 'Filter' problem, and have been stuck a little bit on the edges
part.
I've been trying to solve it using this algorithm:
RGBTRIPLE
called image[height][width]
g(x)
and g(y)
values, calculate the square root of g(x)^2 + g(y)^2
, round it accordingly, and export that value in another matrix image2[height][width]
.The code I'm providing below is my attempt of solving the problem. I used the same verifications (check for corner, edge or middle) as in the blur
algorithm, and it worked.
// Detect edges
void edges(int height, int width, RGBTRIPLE image[height][width])
{
RGBTRIPLE gx, gy;
RGBTRIPLE image2[height][width];
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
gx.rgbtRed = 0;
gx.rgbtGreen = 0;
gx.rgbtBlue = 0;
gy.rgbtRed = 0;
gy.rgbtGreen = 0;
gy.rgbtBlue = 0;
if (i == 0 && j == 0)
{
gx.rgbtRed += 0 * image[i][j].rgbtRed;
gx.rgbtGreen += 0 * image[i][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i][j].rgbtBlue;
gy.rgbtRed += 0 * image[i][j].rgbtRed;
gy.rgbtGreen += 0 * image[i][j].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j].rgbtBlue;
gx.rgbtRed += 0 * image[i+1][j].rgbtRed;
gx.rgbtGreen += 0 * image[i+1][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i+1][j].rgbtBlue;
gy.rgbtRed += 2 * image[i+1][j].rgbtRed;
gy.rgbtGreen += 2 * image[i+1][j].rgbtGreen;
gy.rgbtBlue += 2 * image[i+1][j].rgbtBlue;
gx.rgbtRed += 2 * image[i][j+1].rgbtRed;
gx.rgbtGreen += 2 * image[i][j+1].rgbtGreen;
gx.rgbtBlue += 2 * image[i][j+1].rgbtBlue;
gy.rgbtRed += 0 * image[i][j+1].rgbtRed;
gy.rgbtGreen += 0 * image[i][j+1].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j+1].rgbtBlue;
gx.rgbtRed += image[i+1][j+1].rgbtRed;
gx.rgbtGreen += image[i+1][j+1].rgbtGreen;
gx.rgbtBlue += image[i+1][j+1].rgbtBlue;
gy.rgbtRed += image[i+1][j+1].rgbtRed;
gy.rgbtGreen += image[i+1][j+1].rgbtGreen;
gy.rgbtBlue += image[i+1][j+1].rgbtBlue;
}
else if (i == 0 && j == width-1)
{
gx.rgbtRed += 0 * image[i][j].rgbtRed;
gx.rgbtGreen += 0 * image[i][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i][j].rgbtBlue;
gy.rgbtRed += 0 * image[i][j].rgbtRed;
gy.rgbtGreen += 0 * image[i][j].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j].rgbtBlue;
gx.rgbtRed += -2 * image[i][j-1].rgbtRed;
gx.rgbtGreen += -2 * image[i][j-1].rgbtGreen;
gx.rgbtBlue += -2 * image[i][j-1].rgbtBlue;
gy.rgbtRed += 0 * image[i][j-1].rgbtRed;
gy.rgbtGreen += 0 * image[i][j-1].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j-1].rgbtBlue;
gx.rgbtRed += 0 * image[i+1][j].rgbtRed;
gx.rgbtGreen += 0 * image[i+1][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i+1][j].rgbtBlue;
gy.rgbtRed += 2 * image[i+1][j].rgbtRed;
gy.rgbtGreen += 2 * image[i+1][j].rgbtGreen;
gy.rgbtBlue += 2 * image[i+1][j].rgbtBlue;
gx.rgbtRed += -1 * image[i+1][j-1].rgbtRed;
gx.rgbtGreen += -1 * image[i+1][j-1].rgbtGreen;
gx.rgbtBlue += -1 * image[i+1][j-1].rgbtBlue;
gy.rgbtRed += image[i+1][j-1].rgbtRed;
gy.rgbtGreen += image[i+1][j-1].rgbtGreen;
gy.rgbtBlue += image[i+1][j-1].rgbtBlue;
}
else if (i == height-1 && j == 0)
{
gx.rgbtRed += 0 * image[i][j].rgbtRed;
gx.rgbtGreen += 0 * image[i][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i][j].rgbtBlue;
gy.rgbtRed += 0 * image[i][j].rgbtRed;
gy.rgbtGreen += 0 * image[i][j].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j].rgbtBlue;
gx.rgbtRed += 0 * image[i-1][j].rgbtRed;
gx.rgbtGreen += 0 * image[i-1][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i-1][j].rgbtBlue;
gy.rgbtRed += -2 * image[i-1][j].rgbtRed;
gy.rgbtGreen += -2 * image[i-1][j].rgbtGreen;
gy.rgbtBlue += -2 * image[i-1][j].rgbtBlue;
gx.rgbtRed += image[i-1][j+1].rgbtRed;
gx.rgbtGreen += image[i-1][j+1].rgbtGreen;
gx.rgbtBlue += image[i-1][j+1].rgbtBlue;
gy.rgbtRed += -1 * image[i][j].rgbtRed;
gy.rgbtGreen += -1 * image[i][j].rgbtGreen;
gy.rgbtBlue += -1 * image[i][j].rgbtBlue;
gx.rgbtRed += 2 * image[i][j+1].rgbtRed;
gx.rgbtGreen += 2 * image[i][j+1].rgbtGreen;
gx.rgbtBlue += 2 * image[i][j+1].rgbtBlue;
gy.rgbtRed += 0 * image[i][j+1].rgbtRed;
gy.rgbtGreen += 0 * image[i][j+1].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j+1].rgbtBlue;
}
else if (i == height-1 && j == width-1)
{
gx.rgbtRed += 0 * image[i][j].rgbtRed;
gx.rgbtGreen += 0 * image[i][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i][j].rgbtBlue;
gy.rgbtRed += 0 * image[i][j].rgbtRed;
gy.rgbtGreen += 0 * image[i][j].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j].rgbtBlue;
gx.rgbtRed += 0 * image[i-1][j].rgbtRed;
gx.rgbtGreen += 0 * image[i-1][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i-1][j].rgbtBlue;
gy.rgbtRed += -2 * image[i-1][j].rgbtRed;
gy.rgbtGreen += -2 * image[i-1][j].rgbtGreen;
gy.rgbtBlue += -2 * image[i-1][j].rgbtBlue;
gx.rgbtRed += -1 * image[i-1][j-1].rgbtRed;
gx.rgbtGreen += -1 * image[i-1][j-1].rgbtGreen;
gx.rgbtBlue += -1 * image[i-1][j-1].rgbtBlue;
gy.rgbtRed += -1 * image[i-1][j-1].rgbtRed;
gy.rgbtGreen += -1 * image[i-1][j-1].rgbtGreen;
gy.rgbtBlue += -1 * image[i-1][j-1].rgbtBlue;
gx.rgbtRed += -2 * image[i][j-1].rgbtRed;
gx.rgbtGreen += -2 * image[i][j-1].rgbtGreen;
gx.rgbtBlue += -2 * image[i][j-1].rgbtBlue;
gy.rgbtRed += 0 * image[i-1][j-1].rgbtRed;
gy.rgbtGreen += 0 * image[i-1][j-1].rgbtGreen;
gy.rgbtBlue += 0 * image[i-1][j-1].rgbtBlue;
}
else if (i == 0)
{
gx.rgbtRed += 0 * image[i][j].rgbtRed;
gx.rgbtGreen += 0 * image[i][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i][j].rgbtBlue;
gy.rgbtRed += 0 * image[i][j].rgbtRed;
gy.rgbtGreen += 0 * image[i][j].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j].rgbtBlue;
gx.rgbtRed += -2 * image[i][j-1].rgbtRed;
gx.rgbtGreen += -2 * image[i][j-1].rgbtGreen;
gx.rgbtBlue += -2 * image[i][j-1].rgbtBlue;
gy.rgbtRed += image[i][j-1].rgbtRed;
gy.rgbtGreen += image[i][j-1].rgbtGreen;
gy.rgbtBlue += image[i][j-1].rgbtBlue;
gx.rgbtRed += -1 * image[i+1][j-1].rgbtRed;
gx.rgbtGreen += -1 * image[i+1][j-1].rgbtGreen;
gx.rgbtBlue += -1 * image[i+1][j-1].rgbtBlue;
gy.rgbtRed += image[i+1][j-1].rgbtRed;
gy.rgbtGreen += image[i+1][j-1].rgbtGreen;
gy.rgbtBlue += image[i+1][j-1].rgbtBlue;
gx.rgbtRed += 0 * image[i+1][j].rgbtRed;
gx.rgbtGreen += 0 * image[i+1][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i+1][j].rgbtBlue;
gy.rgbtRed += 2 * image[i+1][j].rgbtRed;
gy.rgbtGreen += 2 * image[i+1][j].rgbtGreen;
gy.rgbtBlue += 2 * image[i+1][j].rgbtBlue;
gx.rgbtRed += image[i+1][j+1].rgbtRed;
gx.rgbtGreen += image[i+1][j+1].rgbtGreen;
gx.rgbtBlue += image[i+1][j+1].rgbtBlue;
gy.rgbtRed += image[i+1][j+1].rgbtRed;
gy.rgbtGreen += image[i+1][j+1].rgbtGreen;
gy.rgbtBlue += image[i+1][j+1].rgbtBlue;
gx.rgbtRed += 2 * image[i][j+1].rgbtRed;
gx.rgbtGreen += 2 * image[i][j+1].rgbtGreen;
gx.rgbtBlue += 2 * image[i][j+1].rgbtBlue;
gy.rgbtRed += 0 * image[i][j+1].rgbtRed;
gy.rgbtGreen += 0 * image[i][j+1].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j+1].rgbtBlue;
}
else if (i == height-1)
{
gx.rgbtRed += 0 * image[i][j].rgbtRed;
gx.rgbtGreen += 0 * image[i][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i][j].rgbtBlue;
gy.rgbtRed += 0 * image[i][j].rgbtRed;
gy.rgbtGreen += 0 * image[i][j].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j].rgbtBlue;
gx.rgbtRed += -2 * image[i][j-1].rgbtRed;
gx.rgbtGreen += -2 * image[i][j-1].rgbtGreen;
gx.rgbtBlue += -2 * image[i][j-1].rgbtBlue;
gy.rgbtRed += 0 * image[i][j-1].rgbtRed;
gy.rgbtGreen += 0 * image[i][j-1].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j-1].rgbtBlue;
gx.rgbtRed += -1 * image[i-1][j-1].rgbtRed;
gx.rgbtGreen += -1 * image[i-1][j-1].rgbtGreen;
gx.rgbtBlue += -1 * image[i-1][j-1].rgbtBlue;
gy.rgbtRed += -1 * image[i-1][j-1].rgbtRed;
gy.rgbtGreen += -1 * image[i-1][j-1].rgbtGreen;
gy.rgbtBlue += -1 * image[i-1][j-1].rgbtBlue;
gx.rgbtRed += 0 * image[i-1][j].rgbtRed;
gx.rgbtGreen += 0 * image[i-1][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i-1][j].rgbtBlue;
gy.rgbtRed += -2 * image[i-1][j].rgbtRed;
gy.rgbtGreen += -2 * image[i-1][j].rgbtGreen;
gy.rgbtBlue += -2 * image[i-1][j].rgbtBlue;
gx.rgbtRed += image[i-1][j+1].rgbtRed;
gx.rgbtGreen += image[i-1][j+1].rgbtGreen;
gx.rgbtBlue += image[i-1][j+1].rgbtBlue;
gy.rgbtRed += 0 * image[i-1][j+1].rgbtRed;
gy.rgbtGreen += 0 * image[i-1][j+1].rgbtGreen;
gy.rgbtBlue += 0 * image[i-1][j+1].rgbtBlue;
gx.rgbtRed += 2 * image[i][j+1].rgbtRed;
gx.rgbtGreen += 2 * image[i][j+1].rgbtGreen;
gx.rgbtBlue += 2 * image[i][j+1].rgbtBlue;
gy.rgbtRed += 0 * image[i][j+1].rgbtRed;
gy.rgbtGreen += 0 * image[i][j+1].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j+1].rgbtBlue;
}
else if (j == 0)
{
gx.rgbtRed += 0 * image[i][j].rgbtRed;
gx.rgbtGreen += 0 * image[i][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i][j].rgbtBlue;
gy.rgbtRed += 0 * image[i][j].rgbtRed;
gy.rgbtGreen += 0 * image[i][j].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j].rgbtBlue;
gx.rgbtRed += 0 * image[i-1][j].rgbtRed;
gx.rgbtGreen += 0 * image[i-1][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i-1][j].rgbtBlue;
gy.rgbtRed += -2 * image[i-1][j].rgbtRed;
gy.rgbtGreen += -2 * image[i-1][j].rgbtGreen;
gy.rgbtBlue += -2 * image[i-1][j].rgbtBlue;
gx.rgbtRed += image[i-1][j+1].rgbtRed;
gx.rgbtGreen += image[i-1][j+1].rgbtGreen;
gx.rgbtBlue += image[i-1][j+1].rgbtBlue;
gy.rgbtRed += -1 * image[i-1][j+1].rgbtRed;
gy.rgbtGreen += -1 * image[i-1][j+1].rgbtGreen;
gy.rgbtBlue += -1 * image[i-1][j+1].rgbtBlue;
gx.rgbtRed += 2 * image[i][j+1].rgbtRed;
gx.rgbtGreen += 2 * image[i][j+1].rgbtGreen;
gx.rgbtBlue += 2 * image[i][j+1].rgbtBlue;
gy.rgbtRed += 0 * image[i][j+1].rgbtRed;
gy.rgbtGreen += 0 * image[i][j+1].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j+1].rgbtBlue;
gx.rgbtRed += image[i+1][j+1].rgbtRed;
gx.rgbtGreen += image[i+1][j+1].rgbtGreen;
gx.rgbtBlue += image[i+1][j+1].rgbtBlue;
gy.rgbtRed += image[i+1][j+1].rgbtRed;
gy.rgbtGreen += image[i+1][j+1].rgbtGreen;
gy.rgbtBlue += image[i+1][j+1].rgbtBlue;
gx.rgbtRed += 0 * image[i+1][j].rgbtRed;
gx.rgbtGreen += 0 * image[i+1][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i+1][j].rgbtBlue;
gy.rgbtRed += 2 * image[i+1][j].rgbtRed;
gy.rgbtGreen += 2 * image[i+1][j].rgbtGreen;
gy.rgbtBlue += 2 * image[i+1][j].rgbtBlue;
}
else if (j == width-1)
{
gx.rgbtRed += 0 * image[i][j].rgbtRed;
gx.rgbtGreen += 0 * image[i][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i][j].rgbtBlue;
gy.rgbtRed += 0 * image[i][j].rgbtRed;
gy.rgbtGreen += 0 * image[i][j].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j].rgbtBlue;
gx.rgbtRed += 0 * image[i-1][j].rgbtRed;
gx.rgbtGreen += 0 * image[i-1][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i-1][j].rgbtBlue;
gy.rgbtRed += -2 * image[i-1][j].rgbtRed;
gy.rgbtGreen += -2 * image[i-1][j].rgbtGreen;
gy.rgbtBlue += -2 * image[i-1][j].rgbtBlue;
gx.rgbtRed += -1 * image[i-1][j-1].rgbtRed;
gx.rgbtGreen += -1 * image[i-1][j-1].rgbtGreen;
gx.rgbtBlue += -1 * image[i-1][j-1].rgbtBlue;
gy.rgbtRed += -1 * image[i-1][j-1].rgbtRed;
gy.rgbtGreen += -1 * image[i-1][j-1].rgbtGreen;
gy.rgbtBlue += -1 * image[i-1][j-1].rgbtBlue;
gx.rgbtRed += -2 * image[i][j-1].rgbtRed;
gx.rgbtGreen += -2 * image[i][j-1].rgbtGreen;
gx.rgbtBlue += -2 * image[i][j-1].rgbtBlue;
gy.rgbtRed += 0 * image[i][j-1].rgbtRed;
gy.rgbtGreen += 0 * image[i][j-1].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j-1].rgbtBlue;
gx.rgbtRed += -1 * image[i+1][j-1].rgbtRed;
gx.rgbtGreen += -1 * image[i+1][j-1].rgbtGreen;
gx.rgbtBlue += -1 * image[i+1][j-1].rgbtBlue;
gy.rgbtRed += image[i+1][j-1].rgbtRed;
gy.rgbtGreen += image[i+1][j-1].rgbtGreen;
gy.rgbtBlue += image[i+1][j-1].rgbtBlue;
gx.rgbtRed += 0 * image[i+1][j].rgbtRed;
gx.rgbtGreen += 0 * image[i+1][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i+1][j].rgbtBlue;
gy.rgbtRed += 2 * image[i+1][j].rgbtRed;
gy.rgbtGreen += 2 * image[i+1][j].rgbtGreen;
gy.rgbtBlue += 2 * image[i+1][j].rgbtBlue;
}
else
{
gx.rgbtRed += 0 * image[i][j].rgbtRed;
gx.rgbtGreen += 0 * image[i][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i][j].rgbtBlue;
gy.rgbtRed += 0 * image[i][j].rgbtRed;
gy.rgbtGreen += 0 * image[i][j].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j].rgbtBlue;
gx.rgbtRed += -1 * image[i-1][j-1].rgbtRed;
gx.rgbtGreen += -1 * image[i-1][j-1].rgbtGreen;
gx.rgbtBlue += -1 * image[i-1][j-1].rgbtBlue;
gy.rgbtRed += -1 * image[i-1][j-1].rgbtRed;
gy.rgbtGreen += -1 * image[i-1][j-1].rgbtGreen;
gy.rgbtBlue += -1 * image[i-1][j-1].rgbtBlue;
gx.rgbtRed += 0 * image[i-1][j].rgbtRed;
gx.rgbtGreen += 0 * image[i-1][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i-1][j].rgbtBlue;
gy.rgbtRed += -2 * image[i-1][j].rgbtRed;
gy.rgbtGreen += -2 * image[i-1][j].rgbtGreen;
gy.rgbtBlue += -2 * image[i-1][j].rgbtBlue;
gx.rgbtRed += image[i-1][j+1].rgbtRed;
gx.rgbtGreen += image[i-1][j+1].rgbtGreen;
gx.rgbtBlue += image[i-1][j+1].rgbtBlue;
gy.rgbtRed += -1 * image[i-1][j+1].rgbtRed;
gy.rgbtGreen += -1 * image[i-1][j+1].rgbtGreen;
gy.rgbtBlue += -1 * image[i-1][j+1].rgbtBlue;
gx.rgbtRed += -2 * image[i][j-1].rgbtRed;
gx.rgbtGreen += -2 * image[i][j-1].rgbtGreen;
gx.rgbtBlue += -2 * image[i][j-1].rgbtBlue;
gy.rgbtRed += 0 * image[i][j-1].rgbtRed;
gy.rgbtGreen += 0 * image[i][j-1].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j-1].rgbtBlue;
gx.rgbtRed += 2 * image[i][j+1].rgbtRed;
gx.rgbtGreen += 2 * image[i][j+1].rgbtGreen;
gx.rgbtBlue += 2 * image[i][j+1].rgbtBlue;
gy.rgbtRed += 0 * image[i][j+1].rgbtRed;
gy.rgbtGreen += 0 * image[i][j+1].rgbtGreen;
gy.rgbtBlue += 0 * image[i][j+1].rgbtBlue;
gx.rgbtRed += -1 * image[i+1][j-1].rgbtRed;
gx.rgbtGreen += -1 * image[i+1][j-1].rgbtGreen;
gx.rgbtBlue += -1 * image[i+1][j-1].rgbtBlue;
gy.rgbtRed += image[i+1][j-1].rgbtRed;
gy.rgbtGreen += image[i+1][j-1].rgbtGreen;
gy.rgbtBlue += image[i+1][j-1].rgbtBlue;
gx.rgbtRed += 0 * image[i+1][j].rgbtRed;
gx.rgbtGreen += 0 * image[i+1][j].rgbtGreen;
gx.rgbtBlue += 0 * image[i+1][j].rgbtBlue;
gy.rgbtRed += 2 * image[i+1][j].rgbtRed;
gy.rgbtGreen += 2 * image[i+1][j].rgbtGreen;
gy.rgbtBlue += 2 * image[i+1][j].rgbtBlue;
gx.rgbtRed += image[i+1][j+1].rgbtRed;
gx.rgbtGreen += image[i+1][j+1].rgbtGreen;
gx.rgbtBlue += image[i+1][j+1].rgbtBlue;
gy.rgbtRed += image[i+1][j+1].rgbtRed;
gy.rgbtGreen += image[i+1][j+1].rgbtGreen;
gy.rgbtBlue += image[i+1][j+1].rgbtBlue;
}
int redVal = (int)round(sqrt(gx.rgbtRed * gx.rgbtRed + gy.rgbtRed * gy.rgbtRed));
int greenVal = (int)round(sqrt(gx.rgbtGreen * gx.rgbtGreen + gy.rgbtGreen * gy.rgbtGreen));
int blueVal = (int)round(sqrt(gx.rgbtBlue * gx.rgbtBlue + gy.rgbtBlue * gy.rgbtBlue));
if (redVal > 255) redVal = 255;
if (greenVal > 255) greenVal = 255;
if (blueVal > 255) blueVal = 255;
image2[i][j].rgbtRed = redVal;
image2[i][j].rgbtGreen = greenVal;
image2[i][j].rgbtBlue = blueVal;
}
}
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
image[i][j].rgbtRed = image2[i][j].rgbtRed;
image[i][j].rgbtGreen = image2[i][j].rgbtGreen;
image[i][j].rgbtBlue = image2[i][j].rgbtBlue;
}
}
return;
}
My code has loads of lines because it uses the same operation multiple times (that's the simplest way I managed to solve the problem).
Also, the constants from the multiplications in the if
statements are just the elements of the matrixes gx
and gy
. I denoted the results of these multiplications with gx
and gy
for no reasons. I didn't want to declare two separate matrixes for these two, so I hard-coded them.
I even tried to verify myself by hand, and also checked if the corners are properly identified using printf()
, and everything worked accordingly.
The problem is, when I used check50
, this was my output:
Also, the provided image called yard.bmp
was converted into a `yardEdges.bmp' that looks like this:
That's a lot of white, from my point of view, and I can't identify any edges from this picture.
First of all, please do not judge my way of coding, I just found this as being the simplest (and also the longest and most boring) way of solving 'edges'.
Also, I don't think the verifications (these 9 if
statements from the code) cause any issue, neither what's in them (the multiplications, etc.). I verified all of them by hand, and I'm pretty sure they're right (I might be wrong, though).
I'm not asking for someone to verify these statements. I'm just curious about what I did wrong, maybe someone can see something I didn't.
Thank you!
You are using wrong data type for your calculations:
RGBTRIPLE gx, gy;
This type is able to hold 8bit values for each channel.
While you add up the separate components for each channel, you can easily get an overflow in one or more channels. This defeats your attempt to limit each channel to 255
later.
To avoid that, simply create another struct:
struct {
uint32_t rgbtRed;
uint32_t rgbtGreen;
uint32_t rgbtBlue;
} gx,gy;
This will allow adding up without overflow.