0
void add(RGBTRIPLE* a, RGBTRIPLE* b){
    a->rgbtRed += b->rgbtRed;
    a->rgbtGreen += b->rgbtGreen;
    a->rgbtBlue += b->rgbtBlue;
}

// Blur image
void blur(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] = image[i][j];
        }
    }
    for(int i=0;i<height;i++){
        for(int j=0;j<width;j++){
            float count = 0.0;
            if (i>0){
                add(&image[i][j], &temp[i-1][j]);
                count++;
            }
            if (j>0){
                add(&image[i][j], &temp[i][j-1]);
                count++;
            }
            if (i>0 && j>0){
                add(&image[i][j], &temp[i-1][j-1]);
                count++;
            }
            if (i>0 && j<width-1){
                add(&image[i][j], &temp[i-1][j+1]);
                count++;
            }
            if (i<height-1 && j>0){
                add(&image[i][j], &(temp[i+1][j-1]));
                count++;
            }
            if (i<height-1 && j<width-1){
                add(&image[i][j], &(temp[i+1][j+1]));
                count++;
            }
            if (i<height-1){
                add(&image[i][j], &(temp[i+1][j]));
                count++;
            }
            if (j<width-1){
                add(&image[i][j], &(temp[i][j+1]));
                count++;
            }
            add(&image[i][j], &temp[i][j]);
            count++;
            image[i][j].rgbtBlue = round(image[i][j].rgbtBlue/count);
            image[i][j].rgbtGreen = round(image[i][j].rgbtGreen/count);
            image[i][j].rgbtRed = round(image[i][j].rgbtRed/count);
        }
    }
    return;
}

Here is my code for the blur part. I don't understand why it's not working, the numbers don't even come close.

0

Consider what happens when blurring a square of pixels, with all having the max value 255 for the red component. While accumulating using a->rgbtRed += b->rgbtRed;, how large of a value can a->rgbtRed hold?

You must log in to answer this question.

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