linumpy.gpu.array_ops#

GPU-accelerated array operations for linumpy.

Provides GPU versions of normalization, clipping, and thresholding. Note: Simple reductions (mean, max) should use numpy directly - GPU offers no benefit.

Functions#

normalize_percentile(image[, p_low, p_high, use_gpu])

GPU-accelerated percentile-based normalization.

normalize_minmax(image[, use_gpu])

GPU-accelerated min-max normalization.

clip_percentile(image[, p_low, p_high, use_gpu])

GPU-accelerated percentile clipping.

compute_percentiles_memory_efficient(image, percentiles)

Compute percentiles using subsampling to reduce memory usage.

compute_nonzero_percentile_memory_efficient(image, ...)

Compute percentile of non-zero values using subsampling.

apply_flatfield_correction(image, flatfield[, ...])

GPU-accelerated flatfield correction.

compute_std_projection(volume[, axis, use_gpu])

GPU-accelerated standard deviation projection.

threshold_otsu(image[, use_gpu])

GPU-accelerated Otsu thresholding.

apply_xy_shift(image, _reference, dy, dx[, use_gpu])

GPU-accelerated XY shift application.

Module Contents#

linumpy.gpu.array_ops.normalize_percentile(image, p_low=1, p_high=99, use_gpu=True)[source]#

GPU-accelerated percentile-based normalization.

Parameters:
  • image (np.ndarray) – Input image

  • p_low (float) – Lower percentile for normalization (0-100)

  • p_high (float) – Upper percentile for normalization (0-100)

  • use_gpu (bool) – Whether to use GPU

Returns:

Normalized image in [0, 1] range

Return type:

np.ndarray

linumpy.gpu.array_ops.normalize_minmax(image, use_gpu=True)[source]#

GPU-accelerated min-max normalization.

Parameters:
  • image (np.ndarray) – Input image

  • use_gpu (bool) – Whether to use GPU

Returns:

Normalized image in [0, 1] range

Return type:

np.ndarray

linumpy.gpu.array_ops.clip_percentile(image, p_low=0.5, p_high=99.5, use_gpu=True)[source]#

GPU-accelerated percentile clipping.

Parameters:
  • image (np.ndarray) – Input image

  • p_low (float) – Lower percentile to clip

  • p_high (float) – Upper percentile to clip

  • use_gpu (bool) – Whether to use GPU

Returns:

Clipped image

Return type:

np.ndarray

linumpy.gpu.array_ops.compute_percentiles_memory_efficient(image, percentiles, use_gpu=True, max_samples=10000000)[source]#

Compute percentiles using subsampling to reduce memory usage.

For large arrays, computing exact percentiles requires sorting the entire array, which can cause memory issues. This function uses random subsampling to estimate percentiles with minimal memory overhead.

Parameters:
  • image (np.ndarray) – Input image

  • percentiles (list) – List of percentiles to compute (0-100)

  • use_gpu (bool) – Whether to use GPU

  • max_samples (int) – Maximum number of samples to use for percentile estimation

Returns:

Computed percentile values

Return type:

list

linumpy.gpu.array_ops.compute_nonzero_percentile_memory_efficient(image, percentile, use_gpu=True, max_samples=10000000)[source]#

Compute percentile of non-zero values using subsampling.

Parameters:
  • image (np.ndarray) – Input image

  • percentile (float) – Percentile to compute (0-100)

  • use_gpu (bool) – Whether to use GPU

  • max_samples (int) – Maximum number of samples to use

Returns:

Computed percentile value

Return type:

float

linumpy.gpu.array_ops.apply_flatfield_correction(image, flatfield, darkfield=None, use_gpu=True)[source]#

GPU-accelerated flatfield correction.

Corrected = (Image - Darkfield) / (Flatfield - Darkfield)

Parameters:
  • image (np.ndarray) – Input image

  • flatfield (np.ndarray) – Flatfield image

  • darkfield (np.ndarray, optional) – Darkfield image

  • use_gpu (bool) – Whether to use GPU

Returns:

Corrected image

Return type:

np.ndarray

linumpy.gpu.array_ops.compute_std_projection(volume, axis=0, use_gpu=True)[source]#

GPU-accelerated standard deviation projection.

Parameters:
  • volume (np.ndarray) – Input volume

  • axis (int) – Axis along which to compute std

  • use_gpu (bool) – Whether to use GPU

Returns:

Standard deviation projection

Return type:

np.ndarray

linumpy.gpu.array_ops.threshold_otsu(image, use_gpu=True)[source]#

GPU-accelerated Otsu thresholding.

Parameters:
  • image (np.ndarray) – Input image

  • use_gpu (bool) – Whether to use GPU

Returns:

Otsu threshold value

Return type:

float

linumpy.gpu.array_ops.apply_xy_shift(image, _reference, dy, dx, use_gpu=True)[source]#

GPU-accelerated XY shift application.

Parameters:
  • image (np.ndarray) – Image to shift

  • reference (np.ndarray) – Reference image (determines output shape)

  • dy (float) – Y shift in pixels

  • dx (float) – X shift in pixels

  • use_gpu (bool) – Whether to use GPU

  • _reference (Any)

Returns:

Shifted image

Return type:

np.ndarray