<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>To get the label, I suppose you may want to use the GetLabelFromTag method. (I never used Dicom before, so I suppose it's what you want).</div><div><br></div><div>GetLabelFromTag and GetValueFromTag have the same problem ... they fail with the same error message.</div><div>It's because in C++ you pass the argument as a string by reference, which you can't in Python.</div><div>I don't know how Swig is wrapping this, so I'll have to investigate a little bit.</div><div><br></div><div>I'll look at this soon and I'll keep you updated.</div><div><br></div><br><div><div>Le 25 juin 2014 à 14:22, Mathew Guilfoyle a écrit :</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div>Fantastic! <br><br></div><div>Is there a way of getting the label as well as the value of the entry? It would be useful for checking that the dictionary entry is the one expected from the tag.<br></div>
<div><br></div><div>Out of interest, do you know the correct way of using the dicomIO.GetValueFromTag() method?<br><br></div><div>Thanks again<br></div><div>Mat<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On 25 June 2014 13:12, Michka Popoff <span dir="ltr"><<a href="mailto:michkapopoff@gmail.com" target="_blank">michkapopoff@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; position: static; z-index: auto; ">
Hi<br>
<br>
I think you can directly access it "python style":<br>
<br>
tilt = metad['0018|1120']<br>
<br>
In fact, the itlMetaDataDictionnary class has a __getitem__ method, which downcasts directly the value [1].<br>
<br>
[1] <a href="https://github.com/InsightSoftwareConsortium/ITK/blob/master/Wrapping/Generators/Python/PyBase/pyBase.i#L173" target="_blank">https://github.com/InsightSoftwareConsortium/ITK/blob/master/Wrapping/Generators/Python/PyBase/pyBase.i#L173</a><br>
<br>
Le 25 juin 2014 à 13:35, Mathew Guilfoyle a écrit :<br>
<div><div class="h5"><br>
> Hi,<br>
><br>
> I need some help with how to correctly access the DICOM meta data dictionary using Python wrapped ITK (v.4.5). My CT scans are scanned with gantry tilt which I need to correct with a shear transform prior to segmenting. The gantry tilt angle is stored in the DICOM header under tag (0018, 1120)<br>
><br>
> example:<br>
><br>
> import itk<br>
><br>
> imdir = '/path/to/images'<br>
> image_t = itk.Image[itk.F, 3]<br>
><br>
> #set up reader<br>
> reader = itk.ImageSeriesReader[image_t].New()<br>
> dicomIO = itk.GDCMImageIO.New()<br>
> dicomFN = itk.GDCMSeriesFileNames.New()<br>
> reader.SetImageIO(dicomIO)<br>
><br>
> #get file names<br>
> dicomFN.SetUseSeriesDetails(True)<br>
> dicomFN.SetDirectory(imdir)<br>
><br>
> #get the first image series<br>
> uids = dicomFN.GetSeriesUIDs()<br>
> fnames = dicomFN.GetFileNames(uids[0])<br>
><br>
> #read in the files<br>
> reader.SetFileNames(fnames)<br>
> reader.Update()<br>
> image = reader.GetOutput()<br>
><br>
> #getting the image works fine. Now to access the meta data dictionary<br>
> metad = dicomIO.GetMetaDataDictionary()<br>
><br>
> #get the entry for gantry tilt using the relevant DICOM tag (0018, 1120)<br>
> tilt = metad.Get('0018|1120')<br>
><br>
> At this point I am stuck. tilt is of type itkMetaDataObjectBase, rather than one the derived classes specific to strings, floats etc.. itkMetaDataObjectBase does not contain the GetMetaDataObjectValue() method, whereas the derived classes do.<br>
><br>
> In the ITK manual, the C++ example uses a dynamic_cast at the type the tag is extracted so that 'tilt' would be of one the derived class types. I have tried the following:<br>
><br>
> sst = itk.MetaDataObject.SS<br>
> tilt.__class__ = sst<br>
> tilt.GetMetaDataObjectValue()<br>
><br>
> casting tilt does work, and the GetMetaDataObjectValue() method is now present as one of tilt's attributes, but just returns an error if executed.<br>
><br>
> The other approach I have tried is to use the dicomIO.GetValueFromTag() method. From the source file the method signature is<br>
><br>
> GetValueFromTag(self, string tag, string value)<br>
><br>
> 'value' is, I presume, meant to be the name of the variable created containing the tilt angle. However if I try:<br>
><br>
> dicomIO.GetValueFromTag('0018|1120', 't_angle')<br>
><br>
> I get the error<br>
> in method 'itkGDCMImageIO_GetValueFromTag', argument 3 of type 'std::string &<br>
><br>
> I would be tremendously grateful for any pointers on how to access the tag data - it must be a routine operation for people using Python/ITK on DICOM images!<br>
><br>
> Many thanks<br>
> Mat<br>
><br>
</div></div>> _____________________________________<br>
> Powered by <a href="http://www.kitware.com/" target="_blank">www.kitware.com</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Kitware offers ITK Training Courses, for more information visit:<br>
> <a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
><br>
> Please keep messages on-topic and check the ITK FAQ at:<br>
> <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://public.kitware.com/mailman/listinfo/insight-users" target="_blank">http://public.kitware.com/mailman/listinfo/insight-users</a><br>
<br>
</blockquote></div><br></div>
</blockquote></div><br></body></html>