Skip to content

verify align hash output with imagehash#26

Merged
aastopher merged 3 commits intomainfrom
stage
Feb 5, 2025
Merged

verify align hash output with imagehash#26
aastopher merged 3 commits intomainfrom
stage

Conversation

@aastopher
Copy link
Owner

aHash

  • Reversed Bit Order:
    Now uses 1 << (63 - i) so that the most significant bit corresponds to the first pixel, matching imagehash’s convention.

mHash

  • Reversed Bit Order:
    Bit order is reversed (using 1 << (63 - i)) to align with other hash types.
  • Optimized Median Calculation:
    Uses Rust’s select_nth_unstable to compute the median in O(n) time instead of a full sort.

dHash

  • Optimized Loop Structure:
    Retrieves the first pixel outside the inner loop (iterating from x = 1 to 8) to avoid redundant calls.

pHash

  • Refined DCT Processing:
    Applies the DCT row‑wise and then column‑wise in place using a fixed‑size temporary array.
  • DC Exclusion in Median Calculation:
    Extracts the top‑left 8×8 DCT coefficients and excludes the DC component when computing the median.
  • O(n) Median Computation:
    Uses select_nth_unstable_by to find median in O(n).
  • Reversed Bit Order:
    Final hash bits are reversed (using 1 << (63 - i)) for consistency with the other algorithms.
  • Result:
    Produces a pHash that is consistent with imagehash.

wHash (Wavelet Hash)

  • Reversed Bit Order:
    Now uses 1 << (63 - i) so that the most significant bit corresponds to the first pixel, matching imagehash’s convention.
  • Haar Transform via dwt Crate:
    Implement Haar transform functions from the dwt crate.
  • Zeroing DC Coefficient:
    Immediately zero out the DC coefficient after forward transform.
  • O(n) Median Calculation:
    Clones transformed pixel vector and uses select_nth_unstable_by to find median in O(n).
  • Hash Generation:
    Iterates over the reconstructed coefficients from the inverse Haar transform, setting bits based on the median, to conform to imagehash’s output.
  • Result:
    Produces a wHash that is consistent with imagehash.

Each change was made to improve performance, and ensure consistent bit ordering across all hash types, and simplify the implementations and align hash output with imagehash for consistency.

@deepsource-io
Copy link

deepsource-io bot commented Feb 5, 2025

Here's the code health analysis summary for commits e2a4b89..f9e65e5. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource Rust LogoRust✅ SuccessView Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 5, 2025

CodSpeed Performance Report

Merging #26 will not alter performance

Comparing stage (f9e65e5) with main (e2a4b89)

Summary

✅ 10 untouched benchmarks

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (350018c) to head (f9e65e5).
Report is 22 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #26   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            5         5           
  Lines          186       174   -12     
=========================================
- Hits           186       174   -12     

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

@aastopher aastopher merged commit 4000d4f into main Feb 5, 2025
10 checks passed
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