The code below spits the following error when trying to compile:
invalid operands to binary expression ('int' and 'RGBTRIPLE')
Basically, I don't know how to properly multiply temp[i][j]
to a factor.
I tried typecasting like 2 * int(temp[i][j])
for instance, but that does not work. How do I go about this one? What do I need to understand more about types in this case?
void edges(int height, int width, RGBTRIPLE image[height][width])
{
RGBTRIPLE temp[height][width];
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
temp[i][j].rgbtRed = image[i][j].rgbtRed;
temp[i][j].rgbtGreen = image[i][j].rgbtGreen;
temp[i][j].rgbtBlue = image[i][j].rgbtBlue;
}
}
int red_gx, green_gx, blue_gx, red_gy, green_gy, blue_gy;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
// Top Left Corner
if (i == 0 && j == 0)
{
red_gx = 0;
green_gx = 0;
blue_gx = 0;
red_gy = 0;
green_gy = 0;
blue_gy = 0;
}
//
// <-- some other elif statements here in between
//
// Any other pixel
else
{
red_gx = (-1 * (temp[i - 1][j - 1])) + temp[i - 1][j + 1] + (-2 * (temp[i][j - 1])) + (2 * (temp[i][j + 1])) + (-1 * (temp[i + 1][j - 1])) + (temp[i + 1][j + 1]);
// green_gx = (-1 * temp[i - 1][j - 1]) + temp[i - 1][j + 1] + (-2 * temp[i][j - 1]) + (2 * temp[i][j + 1]) + (-1 * temp[i + 1][j - 1]) + temp[i + 1][j + 1];
// blue_gx = (-1 * temp[i - 1][j - 1]) + temp[i - 1][j + 1] + (-2 * temp[i][j - 1]) + (2 * temp[i][j + 1]) + (-1 * temp[i + 1][j - 1]) + temp[i + 1][j + 1];
// red_gy = (-1 * temp[i - 1][j - 1]) + (-2 * temp[i - 1][j]) + (-1 * temp[i - 1][j + 1]) + temp[i + 1][j - 1] + (2 * temp[i + 1][j]) + temp[i + 1][j + 1];
// green_gy = (-1 * temp[i - 1][j - 1]) + (-2 * temp[i - 1][j]) + (-1 * temp[i - 1][j + 1]) + temp[i + 1][j - 1] + (2 * temp[i + 1][j]) + temp[i + 1][j + 1];
// blue_gy = (-1 * temp[i - 1][j - 1]) + (-2 * temp[i - 1][j]) + (-1 * temp[i - 1][j + 1]) + temp[i + 1][j - 1] + (2 * temp[i + 1][j]) + temp[i + 1][j + 1];
}
image[i][j].rgbtRed = round(sqrt(pow(round(red_gx), 2) + pow(round(red_gy), 2)));
image[i][j].rgbtGreen = round(sqrt(pow(round(green_gx), 2) + pow(round(green_gy), 2)));
image[i][j].rgbtBlue = round(sqrt(pow(round(blue_gx), 2) + pow(round(blue_gy), 2)));
}
}
return;
}