Skip to main content

Calculate the sharpness of an image with the CPBD metric (Python 3.12+ compatible)

Project description

cpbd-py312

PyPI version Python License

A Python 3.12+ compatible fork of the Cumulative Probability of Blur Detection (CPBD) image sharpness metric. This fork modernizes the original python-cpbd package with updated dependencies and removes deprecated functionality.

About

cpbd-py312 is a modernized fork of the original python-cpbd package, specifically updated to work with Python 3.12 and newer versions. This package implements the Cumulative Probability of Blur Detection (CPBD) metric for no-reference image sharpness assessment.

CPBD is a perceptual-based metric that quantifies image sharpness without requiring a reference image. It estimates the probability of blur detection at each edge in an image and computes the cumulative probability to provide an overall sharpness score.

Key Updates in This Fork

  • Python 3.12 Compatibility: Full support for Python 3.12
  • Modern Dependencies: Updated to use imageio instead of deprecated scipy.ndimage.imread
  • Streamlined Codebase: Removed Python 2 compatibility code and legacy imports
  • Modern Packaging: Uses pyproject.toml for PEP 517/518 compliant packaging

Installation

pip install cpbd-py312

Quick Start

from cpbd import compute
from imageio.v2 import imread
from skimage.color import rgb2gray

# Load image
image = imread('path/to/image.png')

# Convert to grayscale if needed
if len(image.shape) == 3:
    image = rgb2gray(image)

# Calculate CPBD
cpbd_value = compute(image)
print(f'CPBD sharpness: {cpbd_value:.6f}')

Higher values indicate sharper images. The CPBD value ranges from 0 (very blurry) to 1 (very sharp).

Command Line Usage

You can also run CPBD from the command line:

python -m cpbd.compute path/to/image.png

Recent Updates (v1.0.0)

Python 3.12 Support

  • Confirmed support for Python 3.12
  • Dropped support for Python 2.7, 3.5, and 3.6
  • Replaced deprecated scipy.ndimage.imread with imageio.v2.imread
  • Removed __future__ imports and Python 2 compatibility code
  • Added modern pyproject.toml for PEP 517/518 compliance

Updated Dependencies

  • matplotlib >= 3.5.0
  • numpy >= 1.21.0
  • scikit-image >= 0.19.0
  • scipy >= 1.7.0
  • imageio >= 2.9.0

Development

Setup

git clone https://github.com/nawta/python-cpbd-py312.git
cd python-cpbd-py312
pip install -e '.[dev]'

Testing

# Run tests with current Python version
python setup.py test

# Test with Python 3.12
pytest

Performance

The following graph shows the accuracy of this implementation compared to the reference MATLAB implementation when tested on the LIVE Image Quality Assessment Database:

The implementation maintains compatibility with the original MATLAB reference implementation, providing consistent results for image sharpness assessment.

References

If you use this code in your research, please cite:

  • N. D. Narvekar and L. J. Karam, "A No-Reference Image Blur Metric Based on the Cumulative Probability of Blur Detection (CPBD)," IEEE Transactions on Image Processing, vol. 20, no. 9, pp. 2678-2683, Sept. 2011.
  • N. D. Narvekar and L. J. Karam, "An Improved No-Reference Sharpness Metric Based on the Probability of Blur Detection," International Workshop on Video Processing and Quality Metrics for Consumer Electronics (VPQM), January 2010.

License

See LICENSE.txt for details. Please note the copyright statement of the original MATLAB implementation.

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

cpbd_py312-1.0.2.tar.gz (371.0 kB view details)

Uploaded Source

Built Distribution

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

cpbd_py312-1.0.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file cpbd_py312-1.0.2.tar.gz.

File metadata

  • Download URL: cpbd_py312-1.0.2.tar.gz
  • Upload date:
  • Size: 371.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for cpbd_py312-1.0.2.tar.gz
Algorithm Hash digest
SHA256 699f2178b9cab84bb969f03e83f9ccea0f7ffd4865efbe368e5a1c1cb7c0984e
MD5 46b716ad0dd4bce3e29e053ce6881cde
BLAKE2b-256 076d2b9dc7b1938e0b1b34e9117ef6b6b15ce2a23ef86ecbffda45c0d338b897

See more details on using hashes here.

File details

Details for the file cpbd_py312-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: cpbd_py312-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for cpbd_py312-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 30e0bb2f38d3450322cfda4fb08cbb9cd2ddd697d1f35fca59d64b64311f6063
MD5 c0e8a776c6a6d4bf3d9a7bddc2ed6821
BLAKE2b-256 b1ae6242c5372190473afafe0f918e5a3a387812407e707e32edb9cfc0080b1d

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