Skip to content

Instantly share code, notes, and snippets.

@sgsfak
Created May 19, 2026 21:10
Show Gist options
  • Select an option

  • Save sgsfak/79eed861205f75a40757e7a899fdeb65 to your computer and use it in GitHub Desktop.

Select an option

Save sgsfak/79eed861205f75a40757e7a899fdeb65 to your computer and use it in GitHub Desktop.
hash the pixels of a DICOM file
# /// 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