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
|
#include <iostream>
#include <iomanip>
#include <vector>
using InnerVec = std::vector<float>;
using Matrix = std::vector<InnerVec>;
int main()
{
Matrix a
{
{ 1.0, 2.0, 3.0, 4.0 },
{ 5.0, 6.0, 7.0, 8.0 },
{ 9.0, 10.0, 11.0, 12.0 },
{ 13.0, 14.0, 15.0, 16.0 }
};
Matrix binned(2, InnerVec(2));
for (int y = 0; y < 2; ++y)
for (int x = 0; x < 2; ++x)
binned[y][x] = (a[y*2 ][x*2 ]
+ a[y*2 ][x*2+1]
+ a[y*2+1][x*2 ]
+ a[y*2+1][x*2+1]) / 4.0;
std::cout << std::fixed << std::setprecision(2);
for (int y = 0; y < 2; ++y)
{
for (int x = 0; x < 2; ++x)
std::cout << std::setw(6) << binned[y][x] << ' ';
std::cout << '\n';
}
}
|