Skip to main content

BM3D for streak artifact removal in neutron imaging

Project description

Build Status OpenSSF Best Practices Documentation Status PyPI Crates.io DOI

BM3D ORNL

A high-performance BM3D denoising library for neutron imaging, optimized for streak/ring artifact removal from sinograms.

The BM3D algorithm was originally proposed by K. Dabov, A. Foi, V. Katkovnik, and K. Egiazarian in the paper "Image Denoising by Sparse 3D Transform-Domain Collaborative Filtering" (2007).

BM3D ORNL provides a Python API with a Rust backend for efficient, parallel processing of tomography data. Key features:

  • Streak/Ring Artifact Removal: Specialized mode for removing vertical streak artifacts common in neutron and X-ray imaging
  • Multi-Scale Processing: True multi-scale BM3D for handling wide streaks that single-scale cannot capture (based on Mäkinen et al. 2021)
  • Fourier-SVD Method: Alternative fast algorithm (~2.6x faster than BM3D) combining FFT-based energy detection with rank-1 SVD
  • Stack Processing: Efficient batched processing of 3D sinogram stacks
  • High Performance: Rust backend with optimized block matching (integral images, early termination) and transforms (Hadamard, FFT)

How to install

Using Pip

# Core library only
pip install bm3dornl

# With GUI application
pip install bm3dornl[gui]

Supported Platforms

Platform Architecture Library GUI
Linux x86_64
macOS ARM64 (Apple Silicon)

Using Pixi (Development)

pixi install
pixi run build

Usage

from bm3dornl import bm3d_ring_artifact_removal
import numpy as np

# Load sinogram data - 2D (H, W) or 3D stack (N, H, W)
sinogram = np.load("sinogram.npy")

# Standard BM3D denoising (generic white noise)
denoised = bm3d_ring_artifact_removal(sinogram, mode="generic", sigma_random=0.1)

# Streak artifact removal (recommended for ring artifacts)
denoised = bm3d_ring_artifact_removal(sinogram, mode="streak", sigma_random=0.1)

# With custom parameters (all parameters are flat, no dict wrapping)
denoised = bm3d_ring_artifact_removal(
    sinogram,
    mode="streak",
    sigma_random=0.1,
    patch_size=8,           # Patch size (7 or 8 recommended)
    step_size=4,            # Step size for patch extraction
    search_window=40,       # Max search distance
    max_matches=64,         # Similar patches per 3D group
    batch_size=32,          # Batch size for stack processing
)

# Multi-scale BM3D for wide streaks (v0.7.0+)
denoised = bm3d_ring_artifact_removal(
    sinogram,
    mode="streak",
    multiscale=True,        # Enable multi-scale pyramid processing
    num_scales=None,        # Auto-detect (or set explicitly)
    filter_strength=1.0,    # Filtering intensity multiplier
)

Fourier-SVD Method (v0.7.0+)

For faster processing with excellent results on many datasets:

from bm3dornl.fourier_svd import fourier_svd_removal

# Fast streak removal (~2.6x faster than BM3D)
denoised = fourier_svd_removal(
    sinogram,
    fft_alpha=1.0,          # FFT-guided trust factor (0.0 disables FFT guidance)
    notch_width=2.0,        # Gaussian notch filter width
)

Performance

The Rust backend provides high performance for tomography stacks:

Metric Value
Speed ~0.63s per frame (512×512) on Apple Silicon
Memory >50% reduction via chunked processing
Parallelism Zero-overhead parallel processing via Rayon

Key optimizations:

  • Integral image pre-screening for fast block matching
  • Early termination in distance calculations
  • Pre-computed FFT plans
  • Fast Walsh-Hadamard transform for 8×8 patches

Development

We use pixi for development environment management.

  1. Clone repo.
  2. Run pixi run build to compile the Rust backend and install in editable mode.
  3. Run pixi run test to run tests.
  4. Run pixi run bench to run performance benchmarks.
git clone https://github.com/ornlneutronimaging/bm3dornl.git
cd bm3dornl
pixi run build
pixi run test

GUI Application

BM3DORNL includes a standalone GUI application for interactive ring artifact removal.

Installation

pip install bm3dornl[gui]

Or install the GUI separately:

pip install bm3dornl-gui

Launching

bm3dornl-gui

Features

  • Load HDF5 files with tree browser for dataset selection
  • Interactive slice viewer with histogram
  • Side-by-side comparison of original and processed images
  • Real-time parameter adjustment
  • ROI selection for histogram (Shift+drag to select region)
  • Export processed data to TIFF or HDF5

Keyboard Shortcuts

Shortcut Action
Shift+Drag Select ROI for histogram
Scroll Zoom in/out on image
Drag Pan image

Parameter Reference

Parameter Default Description
mode "streak" "generic" for white noise, "streak" for ring artifacts
sigma_random 0.1 Noise standard deviation
patch_size 8 Patch size (7 or 8 recommended)
step_size 4 Step size for patch extraction
search_window 24 Maximum search distance for similar patches
max_matches 16 Maximum similar patches per 3D group
batch_size 32 Batch size for stack processing
streak_sigma_smooth 3.0 Smoothing for streak mode (streak mode only)
multiscale False Enable multi-scale processing for wide streaks
num_scales None Number of scales (auto-detected if None)
filter_strength 1.0 Filtering strength multiplier for multi-scale
debin_iterations 30 Debinning iterations for multi-scale

Fourier-SVD Parameters

Parameter Default Description
fft_alpha 1.0 FFT-guided trust factor (0.0 disables FFT guidance)
notch_width 2.0 Gaussian notch filter width in frequency domain

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

bm3dornl-0.10.0.tar.gz (126.4 kB view details)

Uploaded Source

Built Distributions

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

bm3dornl-0.10.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

bm3dornl-0.10.0-cp314-cp314-macosx_11_0_arm64.whl (910.2 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

bm3dornl-0.10.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

bm3dornl-0.10.0-cp313-cp313-macosx_11_0_arm64.whl (909.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

bm3dornl-0.10.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

bm3dornl-0.10.0-cp312-cp312-macosx_11_0_arm64.whl (909.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file bm3dornl-0.10.0.tar.gz.

File metadata

  • Download URL: bm3dornl-0.10.0.tar.gz
  • Upload date:
  • Size: 126.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bm3dornl-0.10.0.tar.gz
Algorithm Hash digest
SHA256 a729b3471af341cc2674dc6bc6ec07b36fcbd6afbc78fc4011a7c635cfe08218
MD5 7eff2c8b9a3c46f08f8338d5056e0389
BLAKE2b-256 3336ee20056916e5874ea518acad608fa43706475dd283fa072b51569aa00f8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for bm3dornl-0.10.0.tar.gz:

Publisher: release.yml on ornlneutronimaging/bm3dornl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bm3dornl-0.10.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bm3dornl-0.10.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 53fb590c44439cf84e1fe8d5f477d4a68a6201aa1add3de392f6b1cfd08f01c7
MD5 8bd1c23447e74fad70a13bb7043b0260
BLAKE2b-256 2741c99a67e8e2bda44aa255f9432de1a2b12452971d742b21cc61918254f4c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for bm3dornl-0.10.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on ornlneutronimaging/bm3dornl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bm3dornl-0.10.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bm3dornl-0.10.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2372e300fbcbca061a79a97817268ed59dae2a23361116e855a0b5eeefed1801
MD5 eabbdf4e012e34e906fff186ace66cc2
BLAKE2b-256 b7cc9418040e952ea51754713b6ff39be0529f43c18cfbc6ab7bc4f77f23a2d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for bm3dornl-0.10.0-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: release.yml on ornlneutronimaging/bm3dornl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bm3dornl-0.10.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bm3dornl-0.10.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a10a54040df093b76d80fe8c909e4e45d76913b6c9de799f8ebbb2179bb4ed09
MD5 ab21ab2bbddd7f3bb2ca22053244f662
BLAKE2b-256 731cc0892fbca554298cc617c56a14e8596f91b59bd478e5b266f81d3ded1ffe

See more details on using hashes here.

Provenance

The following attestation bundles were made for bm3dornl-0.10.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on ornlneutronimaging/bm3dornl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bm3dornl-0.10.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bm3dornl-0.10.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 856687df5b1f0cda325eeea5e674e26e1da36d71dee2b6271603d9e954ae03b0
MD5 baea97ae09493c6c5828e4ef924124ac
BLAKE2b-256 04354071246cf1c6556a7e2b3599b8e341b493f744bf44a66bee9a14f38eb6d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for bm3dornl-0.10.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on ornlneutronimaging/bm3dornl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bm3dornl-0.10.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bm3dornl-0.10.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e987452fbd147f07c3298a8eb5e81fcdd1b1c813387771e9fb6ddfedaea27613
MD5 8f364311488105bf9ed44ad8b9ef6c52
BLAKE2b-256 3412c89c17614d2df09ab1c5e03bee8f00478e0d420b72652476e090965d8fdd

See more details on using hashes here.

Provenance

The following attestation bundles were made for bm3dornl-0.10.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on ornlneutronimaging/bm3dornl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bm3dornl-0.10.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bm3dornl-0.10.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b0210775487325d7d5eb1050924a7b1ac9addad4f4d89a03ff699eb32e75ae94
MD5 63f08170497347ce7d4c0a13c5737c26
BLAKE2b-256 ffe8c1f93990e2977777a281aeeb922e8c786384fddb893c4d43180356dc533b

See more details on using hashes here.

Provenance

The following attestation bundles were made for bm3dornl-0.10.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on ornlneutronimaging/bm3dornl

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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