I am using the DCMTK (3.6.0) library to get the value of the (0020,0013) tag which is the image number aka the slice number of the serie.
I use the following in a batch script
for /f "tokens=2 delims=[]" %%a in ('@echo. ^|c:\Libs\dcmtk-3.6.0\bin\dcmdump +P "0020,0013" %%i') do (set img_no=%%a)
It usually goes well, but sometimes this value is always set to '0' to the whole serie.
I tried to dump that with this command
C:\Libs\dcmtk-3.6.0\bin>dcmdump +P "0020,0013" PathToInvalideDICOM\img.dcm
(0020,0013) IS [0] # 2, 1 InstanceNumber
(0020,0013) IS [4] # 2, 1 InstanceNumber
(0020,0013) IS [0] # 2, 1 InstanceNumber
C:\Libs\dcmtk-3.6.0\bin>dcmdump +P "0020,0013" PathToCorrectDICOM\img.dcm
(0020,0013) IS [0] # 2, 1 InstanceNumber
(0020,0013) IS [5] # 2, 1 InstanceNumber
As we can see, sometimes the value to get (which is not the '0') is the last. In this case, everything is good. But in some particular cases, the correct value is stored between two '0'.
I also tried with a different dumper (DCM4CHE 2.0.23) and it give me the same result.
I want to know why this is happening. And more than that, how to get the correct value?
Is there a way, in a batch file, to eliminate the 0 until the correct number?
By default, my command line cited above take the last field... I think.
The value ranges in DICOM images are useful as they correlate with the Hounsfield Scale which is a quantitative scale for describing radio-density (or a way of viewing different tissues densities — more explained below) These are the dependencies you will need to have installed on your computer to be able to go through this tutorial
DICOM files typically have a.dcm extension and provides a means of storing data in separate ‘tags’ such as patient information, image/pixel data, the machine used and alot more information (explained below). A DICOM file predominantly consists of a header and image pixel intensity data packed into a single file.
Values with a VR of OB shall be padded with a single trailing NULL byte value (00H) when necessary to achieve even length. All new VRs defined in future versions of DICOM shall be of the same Data Element Structure as defined in Section 7.1.2 (i.e., following the format for VRs such as OB, OW, SQ and UN).
DICOM images may have a wide range from -1000 to +1000 and for humans to be able to see relevant structures within the image a process of windowing is utilized. Fastai provides various dicom_windows so that only specific HU values are displayed on the screen.
Most likely, the extra InstanceNumber tags are part of a dicom sequence and may not be the ones you want.
If you run dcmdump like this:
dcmdump +p +P "0020,0013" PathToInvalideDICOM\img.dcm
You should get the fully scoped output like:
(0008,1111).(0020,0013) IS [0] # 2, 1 InstanceNumber
(0020,0013) IS [1] # 2, 1 InstanceNumber
(5200,9230).(2005,140f).(0020,0013) IS [1] # 2, 1 InstanceNumber
Then it should be a matter of just validating exactly which InstanceNumber you really want (probably the global one)
In a batch file, you probably want to do a findstr to pick out the line. You might want to try:
dcmdump +p +P "0020,0013" PathToInvalideDICOM\img.dcm | findstr /b (0020
To pull out the "global" InstanceNumber tag. Then you should be able to parse the tokens as you have.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With