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

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.1.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.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: srad-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 4b5e7fab331a025551798112621d3038aefec55d12fa80d92f1c81a806a1c6db
MD5 d2cdf1fd69f295db367956a1cb5133a6
BLAKE2b-256 4a2c4a0a258ab7530f03d1b29f24de4f5b142f1833887da0cd48f4d0a8f964c3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: srad-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.0 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 18bfae24770fcf9dd57bc7af3291401059ab13cf3837ac86691a4842fd21954e
MD5 fdcd293448c79f330f4924566ceed3fb
BLAKE2b-256 f56c9632cb29e156069c129bbf77a94ab72e9278c26f33bd19324433a07b07ab

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