Skip to main content

Phase based feature detection and image enhancement

Project description

phasecongruency

Python package for phase-congruency-based feature detection and phase-preserving image enhancement.

Installation

From source with pip:

pip install .

Editable install for development:

pip install -e ".[dev]"

Or with uv:

uv sync --extra dev

GPU backend (PyTorch / Apple Metal MPS):

pip install "phasecongruency[gpu]"

Quick Start

from phasecongruency import phasecongmono, phasecong3, phasesym, step2line

img = step2line(256)

# Fast monogenic phase congruency (defaults)
PC, orientation, phase_type, T = phasecongmono(img)

# Tuned monogenic phase congruency (all key parameters configurable)
PC2, orientation2, phase_type2, T2 = phasecongmono(
    img,
    nscale=5,
    minwavelength=3,
    mult=2.1,
    sigmaonf=0.55,
    k=3.0,
    noisemethod=-1,
    cutoff=0.5,
    g=10.0,
    deviationgain=1.5,
)

# Oriented phase congruency (edge/corner moments)
M, m, or_, feat_type, EO, T3 = phasecong3(
    img,
    nscale=4,
    norient=6,
    minwavelength=3,
    mult=2.1,
    sigmaonf=0.55,
    k=2.0,
    cutoff=0.5,
    g=10.0,
    noisemethod=-1,
)

# Phase symmetry (blob/line-like structures)
phSym, orient, totalEnergy, Tps = phasesym(img)

# Optional GPU backend (auto-selects MPS on Apple Silicon if available)
PC_gpu, orientation_gpu, phase_type_gpu, T_gpu = phasecongmono(
    img,
    backend="auto",
)

# Force Apple Metal backend explicitly
M_gpu, m_gpu, or_gpu, feat_gpu, EO_gpu, T3_gpu = phasecong3(
    img,
    backend="torch-mps",
)

# Low-memory mode when EO outputs are not needed
M_lm, m_lm, or_lm, feat_lm, EO_lm, T_lm = phasecong3(
    img,
    return_eo=False,
)
assert EO_lm is None

backend="auto" falls back to NumPy if PyTorch is not installed.

When PyTorch is available, backend="auto" benchmarks NumPy vs torch once per function + image shape + parameter set, then caches the winner on disk for reuse across runs.

  • Default cache path:
    • macOS/Linux: ~/.cache/phasecongruency/auto_backend_cache.json
    • Windows: %LOCALAPPDATA%\\phasecongruency\\auto_backend_cache.json
  • Override cache path with env var:
    • PHASECONGRUENCY_AUTO_CACHE_PATH=/path/to/cache.json

Parameter Configurability

Core algorithm parameters are exposed as keyword arguments in Python.

  • Use keyword arguments on: phasecongmono, phasecong3, phasesymmono, phasesym, ppdrc, ppdenoise, monofilt, gaborconvolve, highpassmonogenic, and bandpassmonogenic.
  • Default values are defined in each function signature.
  • GPU-capable functions also accept backend ("numpy", "torch", "torch-mps", "auto") and optional device.
  • Inspect any callable signature directly:
from inspect import signature
from phasecongruency import phasecongmono
print(signature(phasecongmono))

Run Tests

UV_CACHE_DIR=.uv-cache uv run pytest tests -q
# or
pytest tests -q

Scope

This repository now maintains the Python implementation only. The historical Julia transpilation/validation workflow has been retired from the active tree.

Validation Provenance

A Julia-vs-Python fidelity validation was completed before this cleanup. See:

  • docs/validation.md

Attribution

This work is based on Peter Kovesi's phase congruency methods and was originally transpiled from:

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

phasecongruency-1.0.5.tar.gz (58.0 kB view details)

Uploaded Source

Built Distribution

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

phasecongruency-1.0.5-py3-none-any.whl (24.9 kB view details)

Uploaded Python 3

File details

Details for the file phasecongruency-1.0.5.tar.gz.

File metadata

  • Download URL: phasecongruency-1.0.5.tar.gz
  • Upload date:
  • Size: 58.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for phasecongruency-1.0.5.tar.gz
Algorithm Hash digest
SHA256 57243181591775e6aba7a025720d31757978a457c0d098ba2a9e1709132c1edc
MD5 e81069e18965336ee0e4498eabd8d0c5
BLAKE2b-256 ac180b35ecf69c7630253071df14972bcd2d90aadc102fd0c9f03912306fd69c

See more details on using hashes here.

Provenance

The following attestation bundles were made for phasecongruency-1.0.5.tar.gz:

Publisher: publish-pypi.yml on sigjhl/ImagePhaseCongruency.py

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

File details

Details for the file phasecongruency-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for phasecongruency-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 98922482319629556cf70041291358effb0e03848d267c38c3635b962196fae6
MD5 79d8cc3a4df9c385caabfc070c4690f3
BLAKE2b-256 353f6574373432d763a63116af63abaff5793b70bc13dabe983afd210ca799da

See more details on using hashes here.

Provenance

The following attestation bundles were made for phasecongruency-1.0.5-py3-none-any.whl:

Publisher: publish-pypi.yml on sigjhl/ImagePhaseCongruency.py

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