Adaptive Thresholding

Python Functions

actag.adaptive_threshold.adaptive_threshold(img: ndarray, kernel_radius: int, offset: float) ndarray

Adaptive thresholding for binarizing 2D images.

Parameters:
  • img (np.ndarray) – 2D image.

  • kernel_radius (int) – Radius of the kernel.

  • offset (float) – Offset value.

Returns:

Binarized image.

Return type:

np.ndarray

actag.adaptive_threshold.adaptive_threshold_multiprocessed(img: ndarray, kernel_radius: int, offset: float, num_processes: int | None = None) ndarray

Same as adaptive_threshold(), but leverages multiprocessing to speed up computation time.

Parameters:
  • img (np.ndarray) – 2D image.

  • kernel_radius (int) – Radius of the kernel.

  • offset (float) – Offset value.

  • num_processes (int, optional) – The number of processes to use. The default is None, which will attempt to use the maximum number of CPUs available, as reported by the OS.

Returns:

Binarized image.

Return type:

np.ndarray

actag.adaptive_threshold.divide_array(arr_len: int, num_sections: int) list

Divides an array into a specified number of sections and returns a list containing the start and end indices for each section.

Parameters:
  • arr_len (int) – Length of the array.

  • num_sections (int) – Number of sections to divide the array into.

Returns:

List containing the start and end indices for each section.

Return type:

list

actag.adaptive_threshold.threshold_sub_image(sub_img: ndarray, kernel_radius: int, offset: float) ndarray

Binarizes a sub-image using adaptive thresholding.

Parameters:
  • sub_img (np.ndarray) – Sub-image to binarize.

  • kernel_radius (int) – Radius of the kernel.

  • offset (float) – Offset value.

Returns:

Binarized sub-image.

Return type:

np.ndarray

Rust Functions

actag.rust_impl.adaptive_threshold()

Rust equivalent of actag.adaptive_threshold.adaptive_threshold().

Parameters:
  • data (Vec<Vec<i32>>) – 2D image.

  • radius (usize) – Radius of the kernel.

  • offset (f64) – Offset value.

Returns:

Binarized image.

Return type:

Vec<Vec<i32>>

actag.rust_impl.adaptive_threshold_multithread()

Rust equivalent of actag.adaptive_threshold.adaptive_threshold_multiprocessed().

Parameters:
  • data (Vec<Vec<i32>>) – 2D image.

  • radius (usize) – Radius of the kernel.

  • offset (f64) – Offset value.

  • cpu_option (Option<usize>) – Number of CPUs to use. If None, all available CPUs will be used.

Returns:

Binarized image.

Return type:

Vec<Vec<i32>>