Skip to main content

Numba-accelerated local 2D Otsu thresholding for 3D images.

Project description

🧠 Local 2D Otsu Thresholding

Local 2D Otsu Thresholding is a Numba-accelerated implementation of a local 2D Otsu thresholding method for 3D images.

This algorithm adapts the 2D Otsu threshold within a sliding 3D window, enabling robust segmentation in datasets with spatially varying intensity distributions.


⚙️ Installation

Install the latest stable version from PyPI:

pip install otsu2D

🚀 Example Usage

import numpy as np
from otsu2D import getBinary

# Create sample 3D image
img = np.random.randint(0, 256, size=(10, 10, 10), dtype=np.uint8)

# Get threshold map and binary image
binary = getBinary(img, window_size=(3, 3, 3),  mean_window_size =(3,3,3))

🖥️ Command Line Usage

Run local 2D Otsu thresholding on a single 3D image stack:

otsu-2d \
  --image path/to/input_stack.tif \
  --window 3 3 3 \
  --mean_window 3 3 3 \
  --outdir outputs \
  --format tif

The output is saved as a binary 3D stack. When using --format tif, the result is saved as a single multi-page TIFF file.

🗂️ Batch Processing

To process all .tif and .tiff files inside a directory and its subdirectories:

otsu-2d-batch \
  --input_dir path/to/input_directory \
  --outdir path/to/output_directory \
  --window 3 3 3 \
  --mean_window 3 3 3 \
  --format tif

The subdirectory structure is preserved in the output directory.

📦 Dependencies

  • NumPy
  • Numba
  • tifffile
  • Matplotlib, optional, only for visualization with --show

Install the required dependencies with:

pip install otsu2D

To include optional plotting support:

pip install "otsu2D[plot]"

📜 License

This project is licensed under the MIT License. See the LICENSE file for details.

🤝 Contributing

Contributions are welcome! If you'd like to fix a bug, add a feature, or improve performance, please open a pull request or contact the maintainers.

💬 Contact

For questions, issues, or feedback, open an issue on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

otsu2d-0.1.1.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

otsu2d-0.1.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file otsu2d-0.1.1.tar.gz.

File metadata

  • Download URL: otsu2d-0.1.1.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for otsu2d-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f7f81cc22d0c35cded883dac0208f3ad0a52216acc7d09d81dd25f9a447ed5d8
MD5 e633a35d13e634832cf28728c5524a41
BLAKE2b-256 c945b447671c8e458b0566728632d85fbe54906d368116ddd42342c924a6ff3f

See more details on using hashes here.

File details

Details for the file otsu2d-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: otsu2d-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for otsu2d-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4d168e1c5f99ba27a9e414c2b26f48e3bd10f20669507e8499e44ad769c3eff0
MD5 51c4bfa91921fa3f1a8b661e4efc0e5f
BLAKE2b-256 c77f468079ee0c69cc6e983b3a77443b8d21c4e5a90646f6998269b62dc7e25b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page