Mercurial > hg > orthanc-tests
comparison Tests/GuessPixelDataVR.py @ 553:6004be7f70a8
added GuessPixelDataVR.py
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sun, 25 Jun 2023 11:46:25 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
552:71096a3e3006 | 553:6004be7f70a8 |
---|---|
1 #!/usr/bin/env python3 | |
2 | |
3 import os | |
4 import sys | |
5 import pydicom | |
6 | |
7 ROOT = os.path.join(os.path.dirname(__file__), '..', 'Database') | |
8 | |
9 for root, dirs, files in os.walk(ROOT): | |
10 for f in files: | |
11 path = os.path.join(root, f) | |
12 | |
13 try: | |
14 ds = pydicom.dcmread(path) | |
15 except: | |
16 continue | |
17 | |
18 ts = ds.file_meta.TransferSyntaxUID | |
19 | |
20 if not 'PixelData' in ds: | |
21 print(path, '=> no pixel data') | |
22 continue | |
23 | |
24 print(path) | |
25 | |
26 if ts == '1.2.840.10008.1.2': | |
27 # Implicit VR Endian | |
28 # https://dicom.nema.org/medical/dicom/current/output/chtml/part05/chapter_A.html#sect_A.1 | |
29 assert(ds['PixelData'].VR == 'OW') | |
30 | |
31 elif ts in [ '1.2.840.10008.1.2.1', | |
32 '1.2.840.10008.1.2.2' ]: | |
33 # Explicit VR Little Endian | |
34 # https://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_A.2.html | |
35 | |
36 # DICOM Big Endian Transfer Syntax (Explicit VR) - Retired, but same rule | |
37 # https://dicom.nema.org/medical/dicom/2016b/output/chtml/part05/sect_A.3.html | |
38 | |
39 if f in [ 'PilatesArgenturGEUltrasoundOsiriX.dcm', | |
40 'KarstenHilbertRF.dcm', | |
41 'Issue143.dcm' ]: | |
42 continue | |
43 | |
44 if ds['BitsAllocated'].value <= 8: | |
45 assert(ds['PixelData'].VR == 'OB') | |
46 else: | |
47 assert(ds['PixelData'].VR == 'OW') | |
48 | |
49 else: | |
50 if (('Beaufix/IM-' in path or | |
51 'Comunix/Ct/IM-' in path or | |
52 'Comunix/Pet/IM-' in path or | |
53 'Knee/T1/IM-' in path or | |
54 'Knee/T2/IM-' in path) and | |
55 ts == '1.2.840.10008.1.2.4.91'): | |
56 # JPEG2k should be "OB", but this is not the case of these modalities | |
57 continue | |
58 | |
59 assert(ds['PixelData'].VR == 'OB') | |
60 |