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