sharpedge.pooling_image

Functions

pooling_image(img, window_size[, pooling_method])

Perform pooling on an image using a specified window size and pooling function.

Module Contents

sharpedge.pooling_image.pooling_image(img, window_size, pooling_method=np.mean)[source]

Perform pooling on an image using a specified window size and pooling function.

Parameters:
  • img (numpy.ndarray) – The input image as a 2D numpy array (grayscale) or 3D numpy array (RGB).

  • window_size (int) – The size of the pooling window (e.g., 10 for 10x10 windows).

  • pooling_method (callable, optional) – The pooling function to apply to each window. Common options include numpy.mean, numpy.median, numpy.max, and numpy.min. Default is numpy.mean.

Returns:

The resized image, reduced by the pooling operation based on the specified window size and pooling function. For grayscale images, the result is a 2D array. For RGB images, the result is a 3D array normalized to the range [0.0, 1.0].

Return type:

numpy.ndarray

Raises:
  • TypeError – If window_size is not an integer or pooling_method is not callable.

  • ValueError – If the image dimensions are not divisible by the window size.

Examples

>>> img = np.random.rand(100, 100)
>>> pooled_img = pooling_image(img, window_size=10, pooling_method=np.mean)

For an RGB image: >>> img_rgb = np.random.rand(100, 100, 3) >>> pooled_img = pooling_image(img_rgb, window_size=20, pooling_method=np.max)