1

Hello. I'm facing a problem trying to compile this code. I got the error msg Invalid operands to binary expression ('int' and 'RGBTRIPLE')

void blur (int height, int width, RGBTRIPLE image[height][width]
{
    RGBTRIPLE copy[height][width]; //Declare copy of image
    for (int i = 0; i < height; i++)
    {
       for (int j = 0; j < width; j++)
       {
        copy[i][j].rgbtRed = image[i][j].rgbtRed;
        copy[i][j].rgbtGreen = image[i][j].rgbtGreen;
        copy[i][j].rgbtBlue = image[i][j].rgbtBlue;
       }
}
//Blur top left corner pixel
image[0][0].rgbtRed = round((copy[0][0].rgbtRed + copy[0][1].rgbtRed + copy[1][0].rgbtRed + copy[1][1]).rgbtRed / 4.0);
image[0][0].rgbtGreen = round((copy[0][0].rgbtGreen + copy[0][1].rgbtGreen + copy[1][0].rgbtGreen + copy[1][1]).rgbtGreen / 4.0);
image[0][0].rgbtBlue = round((copy[0][0].rgbtBlue + copy[0][1].rgbtBlue + copy[1][0].rgbtBlue + copy[1][1]).rgbtBlue / 4.0);

//Blur top right corner pixel
image[0][width-1].rgbtRed = (copy[0][width-1].rgbtRed + copy[0][width-2].rgbtRed + copy[1][width-2].rgbtRed + copy[1][width-1]).rgbtRed / 4.0;
image[0][width-1].rgbtGreen = (copy[0][width-1].rgbtGreen + copy[0][width-2].rgbtGreen + copy[1][width-2].rgbtGreen + copy[1][width-1]).rgbtGreen / 4.0;
image[0][width-1].rgbtBlue = (copy[0][width-1].rgbtBlue + copy[0][width-2].rgbtBlue + copy[1][width-2].rgbtBlue + copy[1][width-1]).rgbtBlue / 4.0;

//Blur bottom left corner pixel
image[height-1][0].rgbtRed = (copy[height-1][0].rgbtRed + copy[height-2][0].rgbtRed + copy[height-2][1].rgbtRed + copy[height-1][1].rgbtRed) / 4.0;
image[height-1][0].rgbtGreen = (copy[height-1][0].rgbtGreen + copy[height-2][0].rgbtGreen + copy[height-2][1].rgbtGreen + copy[height-1][1].rgbtGreen) / 4.0;
image[height-1][0].rgbtBlue = (copy[height-1][0].rgbtBlue + copy[height-2][0].rgbtBlue + copy[height-2][1].rgbtBlue + copy[height-1][1].rgbtBlue) / 4.0;

//Blur bottom right corner pixel
image[height-1][width-1].rgbtRed = (copy[height-1][width-1].rgbtRed + copy[height-1][width-2].rgbtRed + copy[height-2][width-2].rgbtRed + copy[height-2][width-1].rgbtRed) / 4.0;
image[height-1][width-1].rgbtGreen = (copy[height-1][width-1].rgbtGreen + copy[height-1][width-2].rgbtGreen + copy[height-2][width-2].rgbtGreen + copy[height-2][width-1].rgbtGreen) / 4.0;
image[height-1][width-1].rgbtBlue = (copy[height-1][width-1].rgbtBlue + copy[height-1][width-2].rgbtBlue + copy[height-2][width-2].rgbtBlue + copy[height-2][width-1].rgbtBlue) / 4.0;

//Blur upper edge (non-corner) pixels
for (int i = 1; i <= width-2; i++)
{
    image[0][i].rgbtRed = (copy[0][i].rgbtRed + copy[0][i-1].rgbtRed + copy[0][i+1].rgbtRed + copy[1][i-1].rgbtRed + copy[1][i].rgbtRed + copy[1][i+1].rgbtRed)/6;
    image[0][i].rgbtGreen = (copy[0][i].rgbtGreen + copy[0][i-1].rgbtGreen + copy[0][i+1].rgbtGreen + copy[1][i-1].rgbtRed + copy[1][i].rgbtRed + copy[1][i+1].rgbtRed)/6;
    image[0][i].rgbtBlue = (copy[0][i].rgbtBlue + copy[0][i-1].rgbtBlue + copy[0][i+1].rgbtBlue + copy[1][i-1].rgbtBlue + copy[1][i].rgbtBlue + copy[1][i+1].rgbtBlue)/6;
}

//Blur left edge (non-corner) pixels
for (int i = 1; i <= height-2; i++)
{
    image[i][0].rgbtRed = (copy[i][0].rgbtRed + copy[i+1][0].rgbtRed + copy[i-1][0].rgbtRed + copy[i+1][1].rgbtRed + copy[i][1].rgbtRed + copy[i-1][1].rgbtRed)/6;
    image[i][0].rgbtGreen = (copy[i][0].rgbtGreen + copy[i+1][0].rgbtGreen + copy[i-1][0].rgbtGreen + copy[i+1][1].rgbtGreen + copy[i][1].rgbtGreen + copy[i-1][1].rgbtGreen)/6;
    image[i][0].rgbtBlue = (copy[i][0].rgbtBlue + copy[i+1][0].rgbtBlue + copy[i-1][0].rgbtBlue + copy[i+1][1].rgbtBlue + copy[i][1].rgbtBlue + copy[i-1][1].rgbtBlue)/6;
}

//Blur right edge (non-corner) pixels
for (int i = 1; i <= height-2; i++)
{
    image[i][width-1].rgbtRed = (copy[i][width-1].rgbtRed + copy[i+1][width-1].rgbtRed + copy[i-1][width-1].rgbtRed + copy[i+1][width-2].rgbtRed + copy[i][width-2].rgbtRed + copy[i-1][width-2].rgbtRed)/6;
    image[i][width-1].rgbtGreen = (copy[i][width-1].rgbtGreen + copy[i+1][width-1].rgbtGreen + copy[i-1][width-1].rgbtGreen + copy[i+1][width-2].rgbtGreen + copy[i][width-2].rgbtGreen + copy[i-1][width-2].rgbtGreen)/6;
    image[i][width-1].rgbtBlue = (copy[i][width-1].rgbtBlue + copy[i+1][width-1].rgbtBlue + copy[i-1][width-1].rgbtBlue + copy[i+1][width-2].rgbtBlue + copy[i][width-2].rgbtBlue + copy[i-1][width-2].rgbtBlue)/6;
}

//Blur bottom edge (non-corner) pixels
for (int i = 1; i <= width-2; i++)
{
    image[height-1][i].rgbtRed = (copy[height-1][i].rgbtRed + copy[height-1][i-1].rgbtRed + copy[height-1][i+1].rgbtRed + copy[height-2][i-1].rgbtRed + copy[height-2][i].rgbtRed + copy[height-2][i+1].rgbtRed)/6;
    image[height-1][i].rgbtGreen = (copy[height-1][i].rgbtGreen + copy[height-1][i-1].rgbtGreen + copy[height-1][i+1].rgbtGreen + copy[height-2][i-1].rgbtGreen + copy[height-2][i].rgbtGreen + copy[height-2][i+1].rgbtGreen)/6;
    image[height-1][i].rgbtBlue = (copy[height-1][i].rgbtBlue + copy[height-1][i-1].rgbtBlue + copy[height-1][i+1].rgbtBlue + copy[height-2][i-1].rgbtBlue + copy[height-2][i].rgbtBlue + copy[height-2][i+1].rgbtBlue)/6;

}
//Blur middle pixels
for (int i = 1; i <= height-2; i++)
{
    for (int j = 1; j <= width-2; j++)
    {
        image[i][j].rgbtRed = (copy[i-1][j-1].rgbtRed + copy[i-1][j].rgbtRed + copy[i-1][j+1].rgbtRed + copy[i][j-1].rgbtRed + copy[i][j].rgbtRed + copy[i][j+1].rgbtRed + copy[i+1][j-1].rgbtRed + copy[i+1][j].rgbtRed + copy[i+1][j+1].rgbtRed)/9;
        image[i][j].rgbtGreen = (copy[i-1][j-1].rgbtGreen + copy[i-1][j].rgbtGreen + copy[i-1][j+1].rgbtGreen + copy[i][j-1].rgbtGreen + copy[i][j].rgbtGreen + copy[i][j+1].rgbtGreen + copy[i+1][j-1].rgbtGreen + copy[i+1][j].rgbtGreen + copy[i+1][j+1].rgbtGreen)/9;
        image[i][j].rgbtBlue = (copy[i-1][j-1].rgbtBlue + copy[i-1][j].rgbtBlue + copy[i-1][j+1].rgbtBlue + copy[i][j-1].rgbtBlue + copy[i][j].rgbtBlue + copy[i][j+1].rgbtBlue + copy[i+1][j-1].rgbtBlue + copy[i+1][j].rgbtBlue + copy[i+1][j+1].rgbtBlue)/9;
    }
}
return;

}

[enter image description When I try to compile this code, I get the error msg "Invalid operands to binary expression ('int' and 'RGBTRIPLE')"1enter image description here

1 Answer 1

0

Looks like you are trying to use brute force to iterate through each pixel. I advise you to create particular function and use for loops to do the same, as you did to copy image.

You must log in to answer this question.

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