Created
May 19, 2026 21:10
-
-
Save sgsfak/79eed861205f75a40757e7a899fdeb65 to your computer and use it in GitHub Desktop.
hash the pixels of a DICOM file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # /// script | |
| # requires-python = ">=3.14" | |
| # dependencies = [ | |
| # "numpy>=2.4.6", | |
| # "pydicom>=3.0.2", | |
| # "xxhash>=3.7.0", | |
| # ] | |
| # /// | |
| import sys | |
| # from hashlib import sha256 as Hash | |
| from pydicom.pixels import pixel_array | |
| from xxhash import xxh3_64 as Hash | |
| def main(fn): | |
| try: | |
| bs = pixel_array(fn).tobytes() | |
| if not bs: | |
| return "-" | |
| h = Hash() | |
| h.update(bs) | |
| return h.hexdigest() | |
| except Exception: | |
| return "-" | |
| if __name__ == "__main__": | |
| hs = main(sys.argv[1]) | |
| print(hs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment