BB

what I want to do is add the colour value to the next until the end then average it out at the end with 8, but I don't know how to write that.
Last edited on
This is making no sense to me what exactly are you trying to do?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
vector < vector < vector < unsigned char > > > blurred;

int add = 0;

for (int row = 1; row < height; row++) {
    for (int col = 1; col < width; col++) {
        for (int colour = 0; colour < 4; colour++) {

            blurred[row][col][colour];
            blurred[row][col - 1][colour];
            blurred[row][col + 1][colour];
            blurred[row + 1][col][colour];
            blurred[row + 1][col - 1][colour];
            blurred[row + 1][col + 1][colour];
            blurred[row - 1][col - 1][colour];
            blurred[row - 1][col + 1][colour];
            blurred[row - 1][col][colour];

        }
    }
}
That is not my whole code, this part is just for blurring an image. The first 2 for loops pick a pixel in the image, the 3rd for loops takes care of the colour (There are 4 main colours in an image: red, green, blue and alpha)

the instructions after tell the program to check each pixel surrounding the selected pixel. What I want to do next is to tell the program to add all the reds, then average it with 8. Add all the blues and average it with 8 and so on.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const int radius = 1;
for (int y = 0; y < height; y++){
    int begin_y = std::max(y - radius, 0);
    int end_y = std::min(y + (radius + 1), height);
    for (int x = 0; x < width; x++){
        int begin_x = std::max(x - radius, 0);
        int end_x = std::min(x + (radius + 1), width);
        int count = (end_x - begin_x) * (end_y - begin_y);
        for (int color = 0; color < 4; color++){
            int sum = 0;
            for (int y0 = begin_y; y0 < end_y; y0++)
                for (int x0 = begin_x; x0 < end_x; x0++)
                    sum += src[x0][y0][color];
            dst[x][y][color] = sum / count;
        }
    }
}
It's not possible to correctly perform this algorithm in-place. You need a source surface and a destination surface.
Last edited on
I know the corners and sides don't work for my program, I'm just focused on the middle part of the image. Is there a way to add the values of the colours when the programs sifts through the pixels?
Your question is covered in my example.
sorry, I'm a beginner programmer. Can you show me a way with my original program?
No, I can't. Your code is incorrect for several reasons.
Topic archived. No new replies allowed.