1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| int red_mean = 0,green_mean = 0,blue_mean = 0, block_counter = 0;
Point position = Point(0,0), counter = Point(0,0);
//In the image
do
{
do
{
//In the window
do
{
do
{
if((position.y + counter.y) <= image.rows && (position.x + counter.x) <= image.cols)
{
blue_mean += image.at<Vec3b>(position.y + counter.y,position.x + counter.x)[0];
green_mean += image.at<Vec3b>(position.y + counter.y,position.x + counter.x)[1];
red_mean += image.at<Vec3b>(position.y + counter.y,position.x + counter.x)[2];
block_counter++;
}
counter.x++;
}while(counter.x < window_size);
counter.x = 0;
counter.y++;
}while(counter.y < window_size);
counter.y = 0;
//Average is done for the window of size window_size*window_size
//So know we set all the window to the mean value
blue_mean /= block_counter;
green_mean /= block_counter;
red_mean /= block_counter;
block_counter = 0;
for(int y = position.y; y < position.y + window_size; y++)
{
for(int x = position.x; x < position.x + window_size; x++)
{
if(y <= image.rows && x <= image.cols)
{
image.at<Vec3b>(y,x)[0] = blue_mean;
image.at<Vec3b>(y,x)[1] = green_mean;
image.at<Vec3b>(y,x)[2] = red_mean;
}
}
}
position.x += window_size;
}while(position.x < image.cols);
position.x = 0;
position.y += window_size;
}while(position.y < image.rows); |
Partager