DICOM field have more value than expected
Asked Answered
S

2

5

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.

Sidewinder answered 13/10, 2015 at 15:1 Comment(0)
V
6

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.

Valentijn answered 13/10, 2015 at 16:50 Comment(1)
It give me something similar. I still have 3 instance numbers equals to 0,4 and 0. Obviously, I want the 4, wich is on the middle. This tag is the (0020,0013). And I do ('@echo. ^|c:\Libs\dcmtk-3.6.0\bin\dcmdump +p +P "0020,0013" %%i') but still have the last value, the 0 ... How to proceed ?Sidewinder
P
1
  • Add a comparison inside the loop:

    for /f "tokens=2 delims=[]"  %%a in ('
        @echo. ^|c:\Libs\dcmtk-3.6.0\bin\dcmdump +P "0020,0013" %%i
    ') do (
        if not "%%a"=="0" set img_no=%%a
    )
    
  • or filter out the [0] with find:

    for /f "tokens=2 delims=[]"  %%a in ('
        @echo. ^|c:\Libs\dcmtk-3.6.0\bin\dcmdump +P "0020,0013" %%i ^|find /v "[0]"
    ') do set img_no=%%a
    
Polak answered 13/10, 2015 at 15:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.