Python (Simple Hashmap + Brute-Force)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def resultGrid(self, image, threshold):\n        m, n = len(image), len(image[0])\n\n        dict1, result = defaultdict(list), []\n\n        def is_valid_region(r,c):\n            total = 0 \n\n            for i in range(r,r+3):\n                for j in range(c,c+3):\n                    if i+1<r+3 and abs(image[i][j]-image[i+1][j]) > threshold:\n                        return -1 \n                    if j+1<c+3 and abs(image[i][j]-image[i][j+1]) > threshold:\n                        return -1 \n                    total += image[i][j]\n\n            return total//9\n\n\n        for i in range(m):\n            result.append(image[i][:])\n            for j in range(n):\n                if i+3 <= m and j+3 <= n:\n                    average = is_valid_region(i,j)\n                    if average != -1:\n                        for k in range(i,i+3):\n                            for l in range(j,j+3):\n                                dict1[(k,l)].append(average)\n\n        for i in range(m):\n            for j in range(n):\n                if len(dict1[(i,j)]):\n                    result[i][j] = sum(dict1[(i,j)])//len(dict1[(i,j)])\n\n        return result \n\n\n        \n```
['Python3']