vector<vector<int>> imageSmoother(vector<vector<int>>& M) { const int N = 151; vector<vector<int>> V; for (int i = 0; i < M.size(); i++)//x范围M.size()=3 { vector<int> m1 = M[i]; vector<int> m2; for (int j = 0; j < m1.size(); j++)//y范围m1.size()=3 { int m0 = m1[j]; //根据i和j找到周边8个节点 int sum = 0; int count = 0; for (int x = i - 1; x <= i + 1; x++) { for (int y = j - 1; y <= j + 1; y++) { if (x >= 0 && x <= M.size() - 1 && y >= 0 && y <= m1.size() - 1) { sum += M[x][y]; count++; } } } int m = sum / count; m2.push_back(m); } V.push_back(m2); } return V; }