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.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How Does Pooling Transform Images? A Visual Guide to Max, Min & Average Pooling

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 out
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CNNImage ProcessingOpenCVPoolingMax Pooling
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.