Reading Sequence of Items

174 views
Skip to first unread message

Jye Smith

unread,
Oct 17, 2013, 12:02:53 AM10/17/13
to nano...@googlegroups.com
Hi nanodicom,

Im trying to figure out how to use nanodicom to read a sequence. In particular Im trying to read;

(0054,0016) Radiopharmaceutical Information Sequence

Using the below sample code I can return an array but am unable to pull any info. I can read other tags fine and using a different dicom read view the tags in 0054,0016, so I know they are there.

$dicom = Nanodicom::factory($filename, 'simple');
$dicom->parse(array(array(0x0051, 0x0016)));
$dicom->value(0x0054, 0x0016);

Any help (example code) on reading the Tag would be great.

Regards
Jye

Nano.

unread,
Oct 17, 2013, 2:14:05 AM10/17/13
to nano...@googlegroups.com
Hi Jye,

The best advice that I can give you at this point is to take a look at the dumper tool. This method does a recursive dump of elements and sequences: https://github.com/nanodocumet/Nanodicom/blob/master/tools/dumper.php#L115

Basically, the statement "$dicom->value(0x0054, 0x0016);" will return an array of elements, not a value. The elements will be have 2 dimensions, the group, and the element.

Let's say that inside of 0x0054, 0x0016 you have the tag 0x0008, 0x0004, then I think this will work.

$sequence = $dicom->value(0x0054, 0x0016);
$08x04 = $sequence[0x0008][0x0004][0];

I must admit that dealing with sequences is not the greatest strength of Nanodicom. I decided to do everything using arrays instead of objects due to the amount of memory used when using objects. I hope I will be able to have some time in the next months to get back and do some refactoring of the code, but I cannot promise anything at this point.

Cheers and good luck,

Nano.

Jye Smith

unread,
Oct 17, 2013, 6:35:21 PM10/17/13
to nano...@googlegroups.com
Thanks for the reply Nano but Im still having no luck. Below is the code and output Im getting. 0018,0031 should return a 'Fluorodeoxyglucose'. Ive attached the dcm file if that helps.

Using dumper I can see the tag correctly but unfortunately Im still to new to php to be able to look at the dumper source and figure out where Im going wrong.

Cheers
Jye

<?php
require 'nanodicom.php';
$filename = 'C:/test.DCM';


$dicom = Nanodicom::factory($filename, 'simple');
$dicom->parse(array(array(0x0010, 0x0010), array(0x0054, 0x0016)));
echo $dicom->value(0x0010, 0x0010)."\n";
$seq = $dicom->value(0x0054, 0x0016);
echo $seq[0x0018][0x0031][0]."\n";
echo var_dump($seq)."\n";
echo var_dump($seq[0x0018][0x0031][0])."\n";

unset($dicom);
?>

patient0
array(1) {
  [65534]=>
  array(1) {
    [57344]=>
    array(1) {
      [0]=>
      array(8) {
        ["len"]=>
        int(378)
        ["val"]=>
        string(0) ""
        ["vr"]=>
        string(2) "UN"
        ["_vr"]=>
        string(0) ""
        ["bin"]=>
        bool(false)
        ["off"]=>
        int(2538)
        ["_off"]=>
        int(2546)
        ["ds"]=>
        array(0) {
        }
      }
    }
  }
}
NULL 
test.DCM

Nano.

unread,
Oct 17, 2013, 8:11:01 PM10/17/13
to nano...@googlegroups.com
Hi Jye,

The closest I have been able to do is posted in this gist: https://gist.github.com/nanodocumet/7034466 (code pasted below)

<?php
require 'Nanodicom/nanodicom.php';
$filename = 'test.DCM';
 
$dicom = Nanodicom::factory($filename);

$dicom->parse(array(array(0x0010, 0x0010), array(0x0054, 0x0016)));
 
// Get the sequence
$seq = $dicom->value(0x0054, 0x0016);
// Get the items (sequences are grouped in items)
$items = $dicom->dataset_value($seq, 0xFFFE, 0xE000);
// Get the value wanted
$val = $dicom->dataset_value($items, 0x0018, 0x0031);
var_dump($val);
 
unset($dicom);

That should work (update your paths for nanodicom and your file)

Regards!

Nano.



--
You received this message because you are subscribed to the Google Groups "nanodicom" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nanodicom+...@googlegroups.com.
To post to this group, send email to nano...@googlegroups.com.
Visit this group at http://groups.google.com/group/nanodicom.
For more options, visit https://groups.google.com/groups/opt_out.

Jye Smith

unread,
Oct 17, 2013, 8:22:18 PM10/17/13
to nano...@googlegroups.com
BIG UPS NANO!!!

That is perfect and was a great help.

Nano.

unread,
Oct 17, 2013, 8:27:26 PM10/17/13
to nano...@googlegroups.com, nano...@googlegroups.com
Hi Jye,

Glad to hear it worked! In the same token you could read any tag, just check the value you need to read from the dumper tool and traverse the tree.

Cheers,

Nano.

On Oct 17, 2013, at 5:22 PM, Jye Smith <jye....@gmail.com> wrote:

BIG UPS NANO!!!

That is perfect and was a great help.

--

Pedro Argolo Piedade

unread,
Aug 13, 2015, 5:59:00 PM8/13/15
to nanodicom, Carlos Queiroz
Hi Jye and Nano, how are guys?

I have a big problem if Items.

I am used to Maltab objects to acess information.

Matlab example to access the leaf jaw positions: "DCMInfo{m}.BeamSequence.(['Item_', num2str(i)]).ControlPointSequence.Item_1.BeamLimitingDevicePositionSequence.Item_2.LeafJawPositions(1)"

In this case we have sub items of a items...

Who can I use your function to access this?

I need to put givens tags in an array but I am struggling.

Can you help us?

My best regards

Pedro P 

Pedro Argolo Piedade

unread,
Aug 13, 2015, 6:57:17 PM8/13/15
to nanodicom, Carlos Queiroz
Hi Jye and Nano, how are guys?

I have a big problem if Items.

I am used to Maltab objects to acess information.

Matlab example to access the leaf jaw positions: "DCMInfo{m}.BeamSequence.(['Item_', num2str(i)]).ControlPointSequence.Item_1.BeamLimitingDevicePositionSequence.Item_2.LeafJawPositions(1)"

In this case we have sub items of a items...

Who can I use your function to access this?

I need to put givens tags in an array but I am struggling.

Can you help us?

My best regards

Pedro P 

Em quinta-feira, 17 de outubro de 2013 21:11:01 UTC-3, Nano. escreveu:

Nano.

unread,
Aug 18, 2015, 3:14:30 AM8/18/15
to nano...@googlegroups.com, Carlos Queiroz
Hi Pedro,

Sorry for the late response. Have you tried something like the gist in here?

If you have a sample file to try, that will help too.

Thanks,

Nano.

For more options, visit https://groups.google.com/d/optout.

Pedro Argolo Piedade

unread,
Aug 21, 2015, 4:21:52 PM8/21/15
to nano...@googlegroups.com, Carlos Queiroz
Hi Nano sorry for the late answer.

I am sending a file to you. We need to get all beam data from the rtplan and put in an array.
We wanto to display in a Table as this:

Imagem inline 1
this is the array that I use.
Imagem inline 2

I was using Matlab and dicom tag name to access and transfers this files to Excell, but is it slow.

You code is fantastic, fast and very reliable! Congratulations!

I am send the file upload2 that I created with Carlos.

I will have to change to use your code that is better. I told Carlos the way we are using is more confusing and I am loosing information of the Item we are getting.

Thanks again!




You received this message because you are subscribed to a topic in the Google Groups "nanodicom" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nanodicom/AnPWMGpHOo0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nanodicom+...@googlegroups.com.

To post to this group, send email to nano...@googlegroups.com.
Visit this group at http://groups.google.com/group/nanodicom.
For more options, visit https://groups.google.com/d/optout.



--
Pedro Argôlo Piedade
Físico Médico - Dosemed Soluções
Físico Médico - Radioterapia São Sebastião
www.radioterapiass.com.br
+55-048-91672105
pedroar...@gmail.com
skype: pedroargolopie
zello: pedroargolopie
whatsapp: +554891672105
RP.BEXIGA- 20110094_RECIDIVA.dcm
upload2.php

Nano.

unread,
Aug 25, 2015, 6:35:17 PM8/25/15
to nano...@googlegroups.com, Carlos Queiroz
Hi Pedro,

I just wanted to let you know that I have received your response. Please allow me few days to take a look at it and reply accordingly.

Thank you for your compliments about the code.

Best regards,

Nano.

On Aug 21, 2015, at 1:21 PM, Pedro Argolo Piedade <pedroar...@gmail.com> wrote:

Hi Nano sorry for the late answer.

I am sending a file to you. We need to get all beam data from the rtplan and put in an array.
We wanto to display in a Table as this:

<image.png>
this is the array that I use.
<image.png>
<RP.BEXIGA- 20110094_RECIDIVA.dcm>
<upload2.php>

Pedro Argolo Piedade

unread,
Aug 25, 2015, 6:45:26 PM8/25/15
to nano...@googlegroups.com, Carlos Queiroz
Nano I gotta it! Thanks for your time! Best regards!


$filename = $tempFile;
$dicom = Nanodicom::factory ( $filename );
$dicom->parse ();
// FGesq = FractionGroupSequence
$FGseq = $dicom->value ( 0x300A, 0x0070 ); // sequencia
$FGitems = $dicom->read_sequence_items ( $FGseq ); // items
$i = 0;
foreach ( $FGitems as $fgitem ) {
$NumberOfBeams = $dicom->dataset_value ( $fgitem, 0x300A, 0x0080 );
$NumberOfFractionsPlanned = $dicom->dataset_value ( $fgitem, 0x300A, 0x0078 );
// RBseq = ReferencedBeamSequence
$RBSeq = $dicom->dataset_value ( $fgitem, 0x300C, 0x0004 );
if ($RBSeq) // testa de existe
{
$RBitems = $dicom->read_sequence_items ( $RBSeq );
foreach ( $RBitems as $rbitem ) {
$BeamMeterset [$i] = $dicom->dataset_value ( $rbitem, 0x300A, 0x0086 );
$i ++;
}
}
}

Pedro Argolo Piedade

unread,
Jan 24, 2018, 10:55:39 AM1/24/18
to nano...@googlegroups.com, Carlos Queiroz
Hi Nano, how are you my friend?

I have been using you library and testing!

We are using your code and finded a unicode problem.
Imagem inline 1
We need to get the dicom tag InstitutuionName, but as language portugues we use some different caracters. In your system we have the name "Radioterapia São Sebastião",
but the code is given an unreconize caracter "[Radioterapia S�o Sebasti�o]".

  • 00A4E 0x300A:0x00B0 BeamSequence                   SQ 48472 []
    • 00A56 0xFFFE:0xE000 Item                           IT 7234 []
      • 00A5E 0x0008:0x0070 Manufacturer                   LO 22  [Varian Medical Systems]
      • 00A7C 0x0008:0x0080 InstitutionName                LO 26  [Radioterapia S�o Sebasti�o]

I am sending the dicom attached to you. Can we do something about  it? or I need to difine on PHP a new type off unicode.
I tested in another dicom reader to see if was a problem o my computer station that export the dicom.
Imagem inline 2

Thanks again!

My best regards

Pedro P
To unsubscribe from this group and stop receiving emails from it, send an email to nanodicom+unsubscribe@googlegroups.com.

To post to this group, send email to nano...@googlegroups.com.
Visit this group at http://groups.google.com/group/nanodicom.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "nanodicom" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nanodicom/AnPWMGpHOo0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nanodicom+unsubscribe@googlegroups.com.

To post to this group, send email to nano...@googlegroups.com.
Visit this group at http://groups.google.com/group/nanodicom.
For more options, visit https://groups.google.com/d/optout.



--
Pedro Argôlo Piedade
Físico Médico - Dosemed Soluções
Físico Médico - Radioterapia São Sebastião
zello: pedroargolopie
whatsapp: +554891672105

--
You received this message because you are subscribed to the Google Groups "nanodicom" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nanodicom+unsubscribe@googlegroups.com.

To post to this group, send email to nano...@googlegroups.com.
Visit this group at http://groups.google.com/group/nanodicom.
For more options, visit https://groups.google.com/d/optout.
<RP.BEXIGA- 20110094_RECIDIVA.dcm>
<upload2.php>

--
You received this message because you are subscribed to a topic in the Google Groups "nanodicom" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nanodicom/AnPWMGpHOo0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nanodicom+unsubscribe@googlegroups.com.

To post to this group, send email to nano...@googlegroups.com.
Visit this group at http://groups.google.com/group/nanodicom.
For more options, visit https://groups.google.com/d/optout.



--
Pedro Argôlo Piedade
Físico Médico - Dosemed Soluções
Físico Médico - Radioterapia São Sebastião
zello: pedroargolopie
whatsapp: +554891672105



--
Pedro Argôlo Piedade
Físico Médico - Radioterapia São Sebastião
www.radioterapiass.com.br
+55-048-91672105
pedroar...@gmail.com
skype: pedroargolopie
whatsapp: +554891672105
RP.1.2.246.352.71.5.187245169.48292.20180123084308.dcm

Pedro Argolo Piedade

unread,
Jan 24, 2018, 11:28:21 AM1/24/18
to nano...@googlegroups.com, Carlos Queiroz
My Friend I solve the problem!

$InstitutionName[$num_campos] = ($dicom->dataset_value($bgitem, 0x0008, 0x0080) === FALSE) ? 'N/A' : mb_convert_encoding($dicom->dataset_value($bgitem, 0x0008, 0x0080),"UTF-8","ISO-8859-1");

Here the solution!


Thanks

Nano.

unread,
Jan 24, 2018, 11:51:01 AM1/24/18
to nano...@googlegroups.com, Carlos Queiroz
Awesome that you found the solution!

Cheers,

Nano.

Pedro Argolo Piedade

unread,
Jan 24, 2018, 12:26:43 PM1/24/18
to nano...@googlegroups.com, Carlos Queiroz
Cheers mate!
Reply all
Reply to author
Forward
0 new messages