toolbox#

Functions#

_apply_per_batch

_check_image

_clip01

_to_numpy_bhwc

_to_torch_bchw

bilateral_denoise

Bilateral filter (edge-preserving).

clahe_luma

CLAHE on luminance (HSV V-channel).

exposure

Exposure compensation.

gamma_correction

Gamma correction.

gaussian_blur

Gaussian blur with std-dev 'sigma' (pixels).

hist_eq_luma

Global histogram equalization on luminance (HSV V-channel).

hue_shift

Hue shift in degrees, degrees ∈ [-180, 180].

linear_contrast

Linear contrast around 0.5: y = (x - 0.5)*alpha + 0.5, alpha ∈ [0, 3].

median_blur

Median blur with circular footprint radius ∈ {1..5}.

nlm_denoise

Non-Local Means denoising.

saturation

Saturation scale: S' = clip((1+s) * S), with s ∈ [-1, 1], where s=-1 -> grayscale, s=0 -> no change.

sharpen_blur

Sharpen/Blur module.

skimage_unsharp_mask

Unsharp masking from skimage.

sobel_edges_blend

Blend Sobel edges (on luminance) with the original image: out = (1 - alpha) * image + alpha * edges_gray alpha ∈ [0, 1]

white_balance

Improved white balance with per-channel params and luminance normalization.

prt_sim.gymnasium.toolbox._apply_per_batch(img_bhwc: ndarray, fn)[source]#
prt_sim.gymnasium.toolbox._check_image(image: Tensor)[source]#
prt_sim.gymnasium.toolbox._clip01(x: ndarray) ndarray[source]#
prt_sim.gymnasium.toolbox._to_numpy_bhwc(image: Tensor) ndarray[source]#
prt_sim.gymnasium.toolbox._to_torch_bchw(arr: ndarray, like: Tensor) Tensor[source]#
prt_sim.gymnasium.toolbox.bilateral_denoise(image: Tensor, sigma_color: float, sigma_spatial: float) Tensor[source]#

Bilateral filter (edge-preserving). sigma_color ∈ [0, 0.2] (range in [0,1] space), sigma_spatial ∈ [1, 5] (pixels).

prt_sim.gymnasium.toolbox.clahe_luma(image: Tensor, clip_limit: float = 0.01, tile_grid_size: int = 8) Tensor[source]#

CLAHE on luminance (HSV V-channel). clip_limit ∈ [0.001, 0.1], tile_grid_size ∈ [4, 16].

prt_sim.gymnasium.toolbox.exposure(image: Tensor, p: Tensor) Tensor[source]#

Exposure compensation.

Parameters:
  • image – Tensor of shape (3, H, W). Values typically in [0, 1]. dtype float.

  • p – Scalar or (B,) tensor with values in [-3.5, 3.5]

Returns:

Tensor of shape (B, 3, H, W), same dtype/device as img

prt_sim.gymnasium.toolbox.gamma_correction(image: Tensor, gamma: Tensor) Tensor[source]#

Gamma correction.

Parameters:
  • image – Tensor of shape (B, 3, H, W). Values typically in [0, 1]. dtype float.

  • gamma – Scalar or (B,) tensor with values in [0.3333, 3.0]

Returns:

Tensor of shape (B, 3, H, W), same dtype/device as img.

prt_sim.gymnasium.toolbox.gaussian_blur(image: Tensor, sigma: float) Tensor[source]#

Gaussian blur with std-dev ‘sigma’ (pixels). sigma in [0, 5].

prt_sim.gymnasium.toolbox.hist_eq_luma(image: Tensor) Tensor[source]#

Global histogram equalization on luminance (HSV V-channel).

prt_sim.gymnasium.toolbox.hue_shift(image: Tensor, degrees: float) Tensor[source]#

Hue shift in degrees, degrees ∈ [-180, 180].

prt_sim.gymnasium.toolbox.linear_contrast(image: Tensor, alpha: float) Tensor[source]#

Linear contrast around 0.5: y = (x - 0.5)*alpha + 0.5, alpha ∈ [0, 3]. alpha=1 no change; alpha<1 lowers contrast; alpha>1 increases.

prt_sim.gymnasium.toolbox.median_blur(image: Tensor, radius: int) Tensor[source]#

Median blur with circular footprint radius ∈ {1..5}. Applied per-channel.

prt_sim.gymnasium.toolbox.nlm_denoise(image: Tensor, h: float, patch_size: int = 5, patch_distance: int = 6, fast_mode: bool = True) Tensor[source]#

Non-Local Means denoising. h ∈ [0, 0.2], patch_size ∈ {3..7}, patch_distance ∈ {3..10}.

prt_sim.gymnasium.toolbox.saturation(image: Tensor, s: float) Tensor[source]#

Saturation scale: S’ = clip((1+s) * S), with s ∈ [-1, 1], where s=-1 -> grayscale, s=0 -> no change.

prt_sim.gymnasium.toolbox.sharpen_blur(image: Tensor, p: Tensor | float) Tensor[source]#

Sharpen/Blur module.

Implements:

I_out = p * I + (1 - p) * I_blurred, with p in [0, 2]

where I_blurred is computed using the kernel (1/13) * [[1,1,1],[1,5,1],[1,1,1]].

Parameters:
  • image – (B, C, H, W) tensor (float). Any value range. Gradient-safe.

  • p – Scalar float or tensor broadcastable to (B, 1, 1, 1). p=1 -> identity; p<1 -> blur; p>1 -> sharpen (unsharp mask).

Returns:

(B, C, H, W) tensor, same dtype/device as image.

prt_sim.gymnasium.toolbox.skimage_unsharp_mask(image: Tensor, radius: float = 1.0, amount: float = 1.0) Tensor[source]#

Unsharp masking from skimage. radius ∈ [0.5, 5], amount ∈ [0, 3].

prt_sim.gymnasium.toolbox.sobel_edges_blend(image: Tensor, alpha: float = 0.5) Tensor[source]#

Blend Sobel edges (on luminance) with the original image: out = (1 - alpha) * image + alpha * edges_gray alpha ∈ [0, 1]

prt_sim.gymnasium.toolbox.white_balance(image: Tensor, pr: Tensor, pg: Tensor, pb: Tensor) Tensor[source]#

Improved white balance with per-channel params and luminance normalization.

Parameters:
  • img – Tensor of shape (B, 3, H, W). Values typically in [0, 1]. dtype float.

  • pr – Per-image/channel parameters [-0.5, 0.5]. Scalar tensor

  • pg – Per-image/channel parameters [-0.5, 0.5]. Scalar tensor

  • pb – Per-image/channel parameters [-0.5, 0.5]. Scalar tensor

Returns:

Tensor of shape (B, 3, H, W), same dtype/device as img.

Classes#

class prt_sim.gymnasium.toolbox.Toolbox(algorithm_list: ~typing.List = [(<function <lambda>>, {}), (<function exposure>, {'p': (-3.5, 3.5)}), (<function white_balance>, {'pb': (-0.5, 0.5), 'pg': (-0.5, 0.5), 'pr': (-0.5, 0.5)}), (<function gamma_correction>, {'gamma': (0.3333, 3.0)})])[source]#

A collection of image processing algorithms with parameter ranges.

Each algorithm is a function that takes an image tensor and parameters, and returns a processed image tensor.

apply_algorithm(choice: Tensor, params: Tensor, image: Tensor) Tensor[source]#

Apply the selected algorithm with given parameters to the image.

Parameters:
  • choice – Tensor of shape (,) with integer in [0, num_algorithms-1]

  • params – Tensor of shape (num_parameters,) with values in [0, 1]

  • image – Tensor of shape (B, 3, H, W) with values in [0, 1]

Returns:

Processed image tensor of shape (B, 3, H, W) with values in [0, 1]