Skip to content

feat: add Peak Signal-to-Noise Ratio (PSNR) to compression#1028

Open
AliAlimohammadi wants to merge 1 commit intoTheAlgorithms:masterfrom
AliAlimohammadi:add-psnr-compression
Open

feat: add Peak Signal-to-Noise Ratio (PSNR) to compression#1028
AliAlimohammadi wants to merge 1 commit intoTheAlgorithms:masterfrom
AliAlimohammadi:add-psnr-compression

Conversation

@AliAlimohammadi
Copy link
Contributor

Description

Adds a pure-Rust implementation of Peak Signal-to-Noise Ratio (PSNR), a standard metric for measuring the quality of a compressed or reconstructed image relative to its original.

First, the Mean Squared Error (MSE) is computed across all $n$ pixel values:

$$MSE = \frac{1}{n} \sum_{i=1}^{n} (o_i - c_i)^2$$

PSNR is then derived in decibels (dB) as:

$$PSNR = 20 \cdot \log_{10}\left(\frac{PIXEL_MAX}{\sqrt{MSE}}\right)$$

where $PIXEL_MAX = 255$ for an 8-bit image. Returns f64::INFINITY when the two images are identical ($MSE = 0$).

Reference: Peak signal-to-noise ratio — Wikipedia

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I ran cargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.
  • I ran cargo fmt just before my last commit.
  • I ran cargo test just before my last commit and all tests passed.
  • I added my algorithm to the corresponding mod.rs file within its own folder, and in any parent folder(s).
  • I added my algorithm to DIRECTORY.md with the correct link.
  • I checked CONTRIBUTING.md and my code follows its guidelines.

@AliAlimohammadi
Copy link
Contributor Author

@siriak, this is ready to be merged.

Note: CI is currently failing due to pre-existing Clippy warnings in binary_count_trailing_zeros.rs, transposition.rs, and prime_check.rs that are unrelated to this PR. Happy to fix these in a separate commit if the maintainers prefer.

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.06%. Comparing base (8673305) to head (4df7b7e).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1028   +/-   ##
=======================================
  Coverage   96.05%   96.06%           
=======================================
  Files         387      388    +1     
  Lines       29420    29468   +48     
=======================================
+ Hits        28260    28308   +48     
  Misses       1160     1160           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants