Hoffman2:Scripts:dcmheader.py: Difference between revisions

From Center for Cognitive Neuroscience
Jump to navigation Jump to search
 
(25 intermediate revisions by the same user not shown)
Line 1: Line 1:
===Purpose===
==Purpose==


To view and edit a Dicom file header information or header of Dicom files under the same subject folder
To view and edit a Dicom file header information or header of Dicom files under the same subject folder


===Setup Environment===
==Setup Environment==
To use this script, you need to load python module first and export the library location:
To use this script, you need to load python module first and export the library location:
   
   
  module load python/3.6.1_shared
  module load python
module load ccnscripts
  export PYTHONPATH=/u/project/CCN/apps/python_libs/3.6/site-packages/
  export PYTHONPATH=/u/project/CCN/apps/python_libs/3.6/site-packages/


===Usage===
==Usage/Help==
To see the usage of this script
To see the usage of this script
   
   
  python3 /u/project/CCN/apps/scripts/dcmheader.py -h
  dcmheader.py --help


===Options===
or
Print whole header information
dcmheader.py -h
 
Output:
 
usage: dcmheader.py [-h] -f FILE [-p] [-c CHECK] [-u UPDATE] [-v]
optional arguments:
  -h, --help            show this help message and exit
  -f FILE, --file FILE  name of the dcm file
  -p, --print          Option: print full dcm header
  -c CHECK, --check CHECK
                        Option: check specific dcm header item. Ex. (0010,
                        0010)
  -u UPDATE, --update UPDATE
                        Option: update header items. Ex. (0010, 0010)=Joe
                        Bruin
  -v, --verbose        Option: show update logs
 
==Options==
'''Specify target file or folder to be viewed or updated'''
(This option cannot be skipped)
--file (or -f)
 
'''Print out the whole header information'''
  --print (or -p)
  --print (or -p)
Show the full header of a dcm file.
Show the full header of a dcm file.This option does not require any argument. However it does not work towards a folder.
This option does not require any argument. However it does not work towards a folder.
 
python3 /u/project/CCN/apps/scripts/dcmheader.py -f /path/to/my/dicom/file -p (or --print )
Example:
   
   
Example of a part of the output from option --print
dcmheader.py -f /path/to/my/dicom/file -p (or --print )
You'll see similar output as the following from option "--print"
   
   
  (0010, 0010) Patient's Name                      PN: '12345'
  (0010, 0010) Patient's Name                      PN: '12345'
  (0010, 0020) Patient ID                          LO: 12345
  (0010, 0020) Patient ID                          LO: 12345
  (0010, 0030) Patient's Birth Date                DA: '20000101'
  (0010, 0030) Patient's Birth Date                DA: '12345'
  (0010, 0040) Patient's Sex                      CS: 'F'
  (0010, 0040) Patient's Sex                      CS: 'F'
  (0010, 1010) Patient's Age                      AS: '020Y'
  (0010, 1010) Patient's Age                      AS: '020Y'
Line 31: Line 55:
   
   


View specific header items
'''View specific header items before/after you update them'''
  --check (or -c)
  --check (or -c)
View specific header items in a dcm file or the same items in all files inside the subject folder.
View specific header items in a dcm file or the same items in all files inside the subject folder.
Line 40: Line 64:


View a single header item:
View a single header item:
  python3 /u/project/CCN/apps/scripts/dcmheader.py -f /path/to/my/dicom/subject/file -c "(0010, 0010)"
  dcmheader.py -f /path/to/my/dicom/subject/file -c "(0010, 0010)"
   
   
View a single header item in all files under a subject folder by specifying the folder instead of a file:
View a single header item in all files under a subject folder by specifying the folder instead of a file:
  python3 /u/project/CCN/apps/scripts/dcmheader.py -f /path/to/my/dicom/subject/ -c "(0010, 0010)"
  dcmheader.py -f /path/to/my/dicom/subject/ -c "(0010, 0010)"
   
   
View multiple header items in a single file:
View multiple header items in a single file (separate multiple items by space):
  python3 /u/project/CCN/apps/scripts/dcmheader.py -f /path/to/my/dicom/subject/file -c  "(0010, 0010) (0010, 0020)"
  dcmheader.py -f /path/to/my/dicom/subject/file -c  "(0010, 0010) (0010, 0020)"


View multiple header items in all files under one subject folder:
View multiple header items in all files under one subject folder:
  python3 /u/project/CCN/apps/scripts/dcmheader.py -f /path/to/my/dicom/subject/ -c  "(0010, 0010) (0010, 0020)"
  dcmheader.py -f /path/to/my/dicom/subject/ -c  "(0010, 0010) (0010, 0020)"
   
   
Update specific header items
'''Update specific header items'''
  --update (or -u)
  --update (or -u)
Updating specific header items by specifying the tag and new value in format as "tag=new_value"  
Updating specific header items by specifying the tag and new value in format as "tag=new_value"  
Line 58: Line 82:


Update a single item (in this example, change the Patient's Name value to 12345_1):
Update a single item (in this example, change the Patient's Name value to 12345_1):
  python3 /u/project/CCN/apps/scripts/dcmheader.py -f /path/to/my/dicom/subject/file -u "(0010, 0010)=12345_1"
  dcmheader.py -f /path/to/my/dicom/subject/file -u "(0010, 0010)=12345_1"


Update the same item for each file under the same subject folder
Update the same item for each file under the same subject folder
  python3 /u/project/CCN/apps/scripts/dcmheader.py -f /path/to/my/dicom/subject/ -u "(0010, 0010)=12345_1"
  dcmheader.py -f /path/to/my/dicom/subject/ -u "(0010, 0010)=12345_1"
 
Update multiple items (separate multiple items by space)


Update multiple items (separate the multiple items by space)
In this example, change both of the Patient's Name and Patient ID values to 12345_1:
(in this example, change both of the Patient's Name and Patient ID values to 12345_1):
dcmheader.py -f /path/to/my/dicom/subject/file -u "(0010, 0010)=12345_1 (0010, 0020)=12345_1"
python3 /u/project/CCN/apps/scripts/dcmheader.py -f /path/to/my/dicom/subject/file -u "(0010, 0010)=12345_1 (0010, 0020)=12345_1"
   
   
Update multiple items for the whole subject folder:
Update multiple items for the whole subject folder:
python3 /u/project/CCN/apps/scripts/dcmheader.py -f /path/to/my/dicom/subject/ -u "(0010, 0010)=12345_1 (0010, 0020)=12345_1"
dcmheader.py -f /path/to/my/dicom/subject/ -u "(0010, 0010)=12345_1 (0010, 0020)=12345_1"


Show more logs of update process
'''Show more logs of update process'''
  --verbose (or -v)
  --verbose (or -v)


Line 77: Line 102:


Example:
Example:
  python3 /u/project/CCN/apps/scripts/dcmheader.py -f /path/to/my/dicom/subject/file -u "(0010, 0010)=12345_1" -v
  dcmheader.py -f /path/to/my/dicom/subject/file -u "(0010, 0010)=12345_1" -v

Latest revision as of 17:39, 7 October 2021

Purpose

To view and edit a Dicom file header information or header of Dicom files under the same subject folder

Setup Environment

To use this script, you need to load python module first and export the library location:

module load python
module load ccnscripts
export PYTHONPATH=/u/project/CCN/apps/python_libs/3.6/site-packages/

Usage/Help

To see the usage of this script

dcmheader.py --help

or

dcmheader.py -h

Output:

usage: dcmheader.py [-h] -f FILE [-p] [-c CHECK] [-u UPDATE] [-v]
optional arguments:
 -h, --help            show this help message and exit
 -f FILE, --file FILE  name of the dcm file
 -p, --print           Option: print full dcm header
 -c CHECK, --check CHECK
                       Option: check specific dcm header item. Ex. (0010,
                       0010)
 -u UPDATE, --update UPDATE
                       Option: update header items. Ex. (0010, 0010)=Joe
                       Bruin
 -v, --verbose         Option: show update logs

Options

Specify target file or folder to be viewed or updated (This option cannot be skipped)

--file (or -f)

Print out the whole header information

--print (or -p)

Show the full header of a dcm file.This option does not require any argument. However it does not work towards a folder.

Example:

dcmheader.py -f /path/to/my/dicom/file -p (or --print )

You'll see similar output as the following from option "--print"

(0010, 0010) Patient's Name                      PN: '12345'
(0010, 0020) Patient ID                          LO: 12345
(0010, 0030) Patient's Birth Date                DA: '12345'
(0010, 0040) Patient's Sex                       CS: 'F'
(0010, 1010) Patient's Age                       AS: '020Y'

(0010, 0010) is the tag for item “Patient's Name”, you'll need this information for using -c (--check) and -u (--update) options.


View specific header items before/after you update them

--check (or -c)

View specific header items in a dcm file or the same items in all files inside the subject folder. You will need to specify the header tag as the argument in format as "(code1, code2)", however the parentheses are not required. Be aware that double quotation "" is needed. Multiple tags can be specified as the following example

Example:

View a single header item:

dcmheader.py -f /path/to/my/dicom/subject/file -c "(0010, 0010)"

View a single header item in all files under a subject folder by specifying the folder instead of a file:

dcmheader.py -f /path/to/my/dicom/subject/ -c "(0010, 0010)"

View multiple header items in a single file (separate multiple items by space):

dcmheader.py -f /path/to/my/dicom/subject/file -c  "(0010, 0010) (0010, 0020)"

View multiple header items in all files under one subject folder:

dcmheader.py -f /path/to/my/dicom/subject/ -c  "(0010, 0010) (0010, 0020)"

Update specific header items

--update (or -u)

Updating specific header items by specifying the tag and new value in format as "tag=new_value"

Example:

Update a single item (in this example, change the Patient's Name value to 12345_1):

dcmheader.py -f /path/to/my/dicom/subject/file -u "(0010, 0010)=12345_1"

Update the same item for each file under the same subject folder

dcmheader.py -f /path/to/my/dicom/subject/ -u "(0010, 0010)=12345_1"

Update multiple items (separate multiple items by space)

In this example, change both of the Patient's Name and Patient ID values to 12345_1:

dcmheader.py -f /path/to/my/dicom/subject/file -u "(0010, 0010)=12345_1 (0010, 0020)=12345_1"

Update multiple items for the whole subject folder:

dcmheader.py -f /path/to/my/dicom/subject/ -u "(0010, 0010)=12345_1 (0010, 0020)=12345_1"

Show more logs of update process

--verbose (or -v)

Use this only with --update option --update option will only output the converted file names after each update. However with -v option, it can shows the updated result of each updated item.

Example:

dcmheader.py -f /path/to/my/dicom/subject/file -u "(0010, 0010)=12345_1" -v