Skip to content

Filter

The Filter module provides GPU-accelerated image filtering operations.


Gaussian Blur

Apply Gaussian blur using a separable kernel (horizontal then vertical pass).

Example - Light Blur:

from pyimagecuda import load, Filter, save

img = load("photo.jpg")

blurred = Filter.gaussian_blur(img, radius=3)

save(blurred, 'output.jpg')
Light blur

Right-click to download and compare in full size

Example - Heavy Blur:

from pyimagecuda import load, Filter, save

img = load("photo.jpg")

blurred = Filter.gaussian_blur(img, radius=50)

save(blurred, 'output.jpg')
Heavy blur

Right-click to download and compare in full size

Parameters:

  • src (Image): Source image
  • radius (int): Blur kernel radius in pixels (default: 3)
  • sigma (float | None): Gaussian sigma value, auto-calculated if None (default: radius / 3.0)
  • dst_buffer (Image | None): Optional output buffer (default: None)
  • temp_buffer (Image | None): Optional temporary buffer for separable convolution (default: None)

Returns: Blurred image (or None if dst_buffer provided)

Note: temp_buffer is used internally for the separable convolution (horizontal pass). Both buffers must have sufficient capacity.


Sharpen

Enhance image edges and details using unsharp mask.

Example - Subtle Sharpening:

from pyimagecuda import load, Filter, save

img = load("photo.jpg")

sharpened = Filter.sharpen(img, strength=0.5)

save(sharpened, 'output.jpg')
Subtle sharpening

Right-click to download and compare in full size

Example - Strong Sharpening:

from pyimagecuda import load, Filter, save

img = load("photo.jpg")

sharpened = Filter.sharpen(img, strength=2.0)

save(sharpened, 'output.jpg')
Strong sharpening

Right-click to download and compare in full size

Parameters:

  • src (Image): Source image
  • strength (float): Sharpening intensity (default: 1.0)
  • dst_buffer (Image | None): Optional output buffer (default: None)

Returns: Sharpened image (or None if dst_buffer provided)

Recommended values: 1.0-1.5 for photos. Higher values work for specific effects but may introduce artifacts.


Sepia

Apply a warm sepia tone effect to give images a vintage, antique look.

Example - Full Sepia:

from pyimagecuda import load, Filter, save

img = load("photo.jpg")

Filter.sepia(img, intensity=1.0)

save(img, 'output.jpg')
Sepia effect

Right-click to download and compare in full size

Example - Subtle Sepia:

from pyimagecuda import load, Filter, save

img = load("photo.jpg")

Filter.sepia(img, intensity=0.5)

save(img, 'output.jpg')
Subtle sepia

Right-click to download and compare in full size

Parameters:

  • image (Image): Image to modify (in-place)
  • intensity (float): Effect intensity from 0.0 (no effect) to 1.0 (full sepia) (default: 1.0)

Returns: None (modifies image in-place)


Invert

Invert all colors to create a photographic negative effect.

Example:

from pyimagecuda import load, Filter, save

img = load("photo.jpg")

Filter.invert(img)

save(img, 'output.jpg')
Inverted colors

Right-click to download and compare in full size

Parameters:

  • image (Image): Image to modify (in-place)

Returns: None (modifies image in-place)


Threshold

Convert image to pure black and white based on luminance threshold.

Example - Medium Threshold:

from pyimagecuda import load, Filter, save

img = load("photo.jpg")

Filter.threshold(img, value=0.5)

save(img, 'output.jpg')
Threshold effect

Right-click to download and compare in full size

Example - Low Threshold (More White):

from pyimagecuda import load, Filter, save

img = load("photo.jpg")

Filter.threshold(img, value=0.3)

save(img, 'output.jpg')
Low threshold

Right-click to download and compare in full size

Parameters:

  • image (Image): Image to modify (in-place)
  • value (float): Threshold value from 0.0 to 1.0 (default: 0.5)

Returns: None (modifies image in-place)

Behavior: Pixels brighter than the threshold become white, others become black. Lower values produce more white areas; higher values produce more black areas.


Solarize

Create a psychedelic effect by inverting colors above a luminance threshold.

Example - Medium Threshold:

from pyimagecuda import load, Filter, save

img = load("photo.jpg")

Filter.solarize(img, threshold=0.5)

save(img, 'output.jpg')
Solarize effect

Right-click to download and compare in full size

Example - Low Threshold:

from pyimagecuda import load, Filter, save

img = load("photo.jpg")

Filter.solarize(img, threshold=0.3)

save(img, 'output.jpg')
Solarize low threshold

Right-click to download and compare in full size

Parameters:

  • image (Image): Image to modify (in-place)
  • threshold (float): Luminance threshold from 0.0 to 1.0 (default: 0.5)

Returns: None (modifies image in-place)

Behavior: Only pixels brighter than the threshold are inverted, creating a distinctive retro/psychedelic look.


Sobel

Detect edges using the Sobel operator to create an edge map.

Example:

from pyimagecuda import load, Filter, save

img = load("photo.jpg")

edges = Filter.sobel(img)

save(edges, 'output.jpg')
Sobel edge detection

Right-click to download and compare in full size

Parameters:

  • src (Image): Source image
  • dst_buffer (Image | None): Optional output buffer (default: None)

Returns: New image with detected edges (or None if dst_buffer provided)

Output: Black and white image where white indicates detected edges.


Emboss

Apply an emboss (relief) effect to create a 3D raised appearance.

Example - Normal Strength:

from pyimagecuda import load, Filter, save

img = load("photo.jpg")

embossed = Filter.emboss(img, strength=1.0)

save(embossed, 'output.jpg')
Emboss effect

Right-click to download and compare in full size

Example - Strong Emboss:

from pyimagecuda import load, Filter, save

img = load("photo.jpg")

embossed = Filter.emboss(img, strength=2.0)

save(embossed, 'output.jpg')
Strong emboss

Right-click to download and compare in full size

Parameters:

  • src (Image): Source image
  • strength (float): Effect intensity (default: 1.0)
  • dst_buffer (Image | None): Optional output buffer (default: None)

Returns: New embossed image (or None if dst_buffer provided)

Recommended values: 0.5-2.0 for most images. Higher values create more pronounced relief.


Buffer Reuse

Reuse buffers for batch processing to avoid allocations.

Example:

from pyimagecuda import Image, load, Filter, save

# Pre-allocate buffers with sufficient capacity (e.g. 1920x1080)
dst = Image(1920, 1080)
temp = Image(1920, 1080)

for file in files:
    src = load(file)
    # Buffers automatically adjust their logical dimensions
    # provided they have enough capacity
    Filter.gaussian_blur(src, radius=5,
                         dst_buffer=dst,
                         temp_buffer=temp)
    save(dst, f"blurred_{file}")
    src.free()

dst.free()
temp.free()

When using buffers, operations are in-place (modify dst_buffer directly) and return None. The buffers automatically adjust their logical dimensions to match the operation result, provided they have enough capacity.