How Does Pooling Transform Images? A Visual Guide to Max, Min & Average Pooling
This article explains the concept of pooling in convolutional neural networks, illustrates max, min, and average pooling with visual examples, discusses window size and stride choices, and provides Python code for each pooling method using NumPy and OpenCV.
Pooling, or "池化" in Chinese, is a common operation in neural networks, especially convolutional neural networks (CNNs). The most frequently used variant is Max Pooling, which selects the maximum value within a sliding window.
Pooling windows are not limited to 2×2; sizes such as 3×3, 5×5, etc., are also valid, and the stride (step size) can be adjusted accordingly. Besides neural networks, pooling can be used to create a mosaic effect on images.
Applying Max Pooling to an example image yields the following result:
Min Pooling and Average Pooling work similarly, differing only in the aggregation function used.
Min Pooling example:
Average Pooling example (which often looks more natural, though results may vary with different images):
Below are Python implementations of the three pooling operations. Since the images have multiple color channels, remember to process each channel separately.
import cv2
import numpy as np
def average_pooling(img, G=5):
out = img.copy()
H, W, C = img.shape
Nh = H // G
Nw = W // G
for y in range(Nh):
for x in range(Nw):
for c in range(C):
out[G*y:G*(y+1), G*x:G*(x+1), c] = np.mean(out[G*y:G*(y+1), G*x:G*(x+1), c]).astype(np.int64)
return out def max_pooling(img, G=5):
out = img.copy()
H, W, C = img.shape
Nh = H // G
Nw = W // G
for y in range(Nh):
for x in range(Nw):
for c in range(C):
out[G*y:G*(y+1), G*x:G*(x+1), c] = np.max(out[G*y:G*(y+1), G*x:G*(x+1), c]).astype(np.int64)
return out def min_pooling(img, G=5):
out = img.copy()
H, W, C = img.shape
Nh = H // G
Nw = W // G
for y in range(Nh):
for x in range(Nw):
for c in range(C):
out[G*y:G*(y+1), G*x:G*(x+1), c] = np.min(out[G*y:G*(y+1), G*x:G*(x+1), c]).astype(np.int64)
return outSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
