Skip to main content

Speckle Reducing Anisotropic Diffusion - Python implementation

Project description

SRAD - Speckle Reducing Anisotropic Diffusion

Python 3.6+ License: MIT

A Python implementation of the Speckle Reducing Anisotropic Diffusion (SRAD) algorithm for denoising images affected by speckle noise, commonly found in ultrasound, SAR (Synthetic Aperture Radar), and other coherent imaging systems.

Example: Noisy vs Denoised


๐Ÿ“– About

This package is a Python port of the original MATLAB implementation by Xingorno. The SRAD algorithm is based on anisotropic diffusion, which smooths homogeneous regions while preserving edges โ€” making it ideal for speckle reduction without blurring important structures.

How It Works

SRAD extends the classic Perona-Malik anisotropic diffusion by incorporating a speckle-sensitive diffusion coefficient. The algorithm iteratively applies a diffusion process where:

  • Homogeneous regions (high speckle) โ†’ Strong smoothing
  • Edge regions (low speckle, high gradient) โ†’ Preserved

The mathematical model follows:

$$\frac{\partial I}{\partial t} = \text{div}[c(q) \nabla I]$$

Where $c(q)$ is the diffusion coefficient computed from the instantaneous coefficient of variation $q$.


๐Ÿš€ Installation

From PyPI (coming soon)

pip install srad

From Source

git clone https://github.com/Keno-00/Speckle-Reducing-Anisotropic-Diffusion-SRAD.git
cd Speckle-Reducing-Anisotropic-Diffusion-SRAD
pip install .

๐Ÿ’ป Usage

As a Library

import cv2
import srad

# Load your grayscale image
img = cv2.imread('path/to/image.png', cv2.IMREAD_GRAYSCALE)

# SRAD Parameters
iteration_max = 200    # Number of diffusion iterations
time_step = 0.05       # Time step per iteration (stability: keep โ‰ค 0.25)
decay_factor = 1       # Controls how fast edges are "locked in"

# Apply SRAD denoising
denoised = srad.SRAD(img, iteration_max, time_step, decay_factor)

# Save result
cv2.imwrite('denoised.png', denoised)

Command Line

Run the built-in example on noisyImage.png:

python -m srad

โš™๏ธ Parameters

Parameter Type Description Recommended
iterationMaxStep int Maximum number of diffusion iterations 100-300
timeSize float Time step size (affects stability and speed) 0.05-0.15
decayFactor float Exponential decay for the diffusion coefficient 1.0

Tips:

  • Higher iterationMaxStep โ†’ More smoothing, longer runtime
  • Larger timeSize โ†’ Faster convergence, but may become unstable if > 0.25
  • Higher decayFactor โ†’ Edges lock in faster

๐Ÿ“ Repository Structure

.
โ”œโ”€โ”€ srad/                    # Python package
โ”‚   โ”œโ”€โ”€ __init__.py          # SRAD algorithm implementation
โ”‚   โ””โ”€โ”€ __main__.py          # CLI entry point
โ”œโ”€โ”€ SpeckleReducingAD.m      # Original MATLAB implementation (general)
โ”œโ”€โ”€ SpeckleReducingAD_New.m  # Original MATLAB implementation (optimized)
โ”œโ”€โ”€ testSRAD.m               # MATLAB test script
โ”œโ”€โ”€ noisyImage.png           # Example input image
โ”œโ”€โ”€ denoised.png             # Example output image
โ”œโ”€โ”€ setup.py                 # Package configuration
โ”œโ”€โ”€ pyproject.toml           # Build system configuration
โ”œโ”€โ”€ LICENSE                  # MIT License
โ””โ”€โ”€ README.md                # This file

๐Ÿ“š References

This implementation is based on the following papers:

  1. Yu, Y., & Acton, S. T. (2002). Speckle reducing anisotropic diffusion. IEEE Transactions on Image Processing, 11(11), 1260-1270.
    ๐Ÿ“„ IEEE Xplore

  2. Perona, P., & Malik, J. (1990). Scale-space and edge detection using anisotropic diffusion. IEEE Transactions on Pattern Analysis and Machine Intelligence, 12(7), 629-639.
    ๐Ÿ“„ IEEE Xplore


๐Ÿ™ Acknowledgments

This project is a fork of the original repository, ported to Python for easier integration into image processing pipelines.


๐Ÿ“„ License

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

The original MATLAB implementation by Xingorno is also under the MIT License.

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

srad-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

srad-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file srad-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for srad-0.1.0.tar.gz
Algorithm Hash digest
SHA256 19994481379a3a5beea24ae4da14de49e0913b7becf18a8b3d5564a72642e491
MD5 a05614023e5b4b9cc24b221ec9ac3945
BLAKE2b-256 6bbb861213bbf9a25aa18eed67e7b571a28f99acf9828ef3c22f6db6ce41ef47

See more details on using hashes here.

File details

Details for the file srad-0.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for srad-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 99ea379026f1922560e0244a00560385c121404d6cfff59007dc6e760e4d6b5c
MD5 27971a378ff264033e1f4b208c7dd8e8
BLAKE2b-256 80f38793cf51305d7e3f15cbb9b2c6b9bb6f43f7440ff608450deb328a367cf3

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