Just do a brute force
Code\n\nclass Solution {\npublic:\n    vector<vector<int>> resultGrid(vector<vector<int>>& image, int threshold) {\n        map<pair<int,int>,vector<int>> mp;\n
# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> resultGrid(vector<vector<int>>& image, int threshold) {\n        map<pair<int,int>,vector<int>> mp;\n        int m=image.size();\n        int n=image[0].size();\n        int delrow[]={-1,0,1,0};\n        int delcol[]={0,1,0,-1};\n        for(int i=0;i<m-2;i++)\n        {\n            for(int j=0;j<n-2;j++)\n            {\n                bool isRegion=true;\n                int sum=0;\n                for(int k=i;k<i+3;k++)\n                {\n                    for(int l=j;l<j+3;l++)\n                    {\n                        sum+=image[k][l];\n                        for(int z=0;z<4;z++)\n                        {\n                            int nrow=k+delrow[z];\n                            int ncol=l+delcol[z];\n                            if(nrow>=0 && nrow<m && ncol>=0 && ncol<n && nrow>=i && nrow<i+3 && ncol>=j && ncol<j+3)\n                            {\n                                if(abs(image[nrow][ncol]-image[k][l])>threshold) \n                                {\n                                    isRegion=false;\n                                    break;\n                                }\n                            }\n                        }\n                        if(!isRegion) break;\n                    }\n                    if(!isRegion) break;\n                }\n                if(isRegion)\n                {\n                    for(int k=i;k<i+3;k++)\n                    {\n                        for(int l=j;l<j+3;l++)\n                        {\n                            mp[{k,l}].push_back(sum/9);\n                        }\n                    }\n                }\n            }\n        }\n        for(int i=0;i<m;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                int sum=0;\n                int size=0;\n                for(auto it:mp[{i,j}])\n                {\n                    sum+=it;\n                    size++;\n                }\n                image[i][j]=size>0?sum/size:image[i][j];\n            }\n        }\n        return image;\n    }\n};\n```
['C++']