<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi<div><br></div><div>I made a patch adding the new feature [1].</div><div><br></div><div>The new syntax will be:</div><div><span class="pln" style="font-family: monospace; font-size: 11px; white-space: pre;">found</span><span class="pun" style="color: rgb(68, 68, 0); font-family: monospace; font-size: 11px; white-space: pre;">,</span><span class="pln" style="font-family: monospace; font-size: 11px; white-space: pre;"> value </span><span class="pun" style="color: rgb(68, 68, 0); font-family: monospace; font-size: 11px; white-space: pre;">=</span><span class="pln" style="font-family: monospace; font-size: 11px; white-space: pre;"> dicomIO</span><span class="pun" style="color: rgb(68, 68, 0); font-family: monospace; font-size: 11px; white-space: pre;">.</span><span class="typ" style="color: rgb(68, 0, 68); font-weight: bold; font-family: monospace; font-size: 11px; white-space: pre;">GetValueFromTag</span><span class="pun" style="color: rgb(68, 68, 0); font-family: monospace; font-size: 11px; white-space: pre;">(</span><span class="str" style="color: rgb(0, 102, 0); font-family: monospace; font-size: 11px; white-space: pre;">"0010|0010"</span><span class="pun" style="color: rgb(68, 68, 0); font-family: monospace; font-size: 11px; white-space: pre;">,</span><span class="pln" style="font-family: monospace; font-size: 11px; white-space: pre;"> </span><span class="str" style="color: rgb(0, 102, 0); font-family: monospace; font-size: 11px; white-space: pre;">""</span><span class="pun" style="color: rgb(68, 68, 0); font-family: monospace; font-size: 11px; white-space: pre;">)</span></div><div><br></div><div>found is a bool telling you if the value/tag was found</div><div>value is the returned value. It’s a little bit different than in c++ were this method returns only the bool.</div><div><br></div><div>[1] <a href="http://review.source.kitware.com/#/c/15954/">http://review.source.kitware.com/#/c/15954/</a></div><div><br></div><div>Michka</div><div><br></div><div><br><div><div>On 29 juin 2014, at 03:58, Mathew Guilfoyle <<a href="mailto:mrguilfoyle@gmail.com">mrguilfoyle@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div>Thanks very much for looking into this; look forward to the fix.<br><br></div><div>Cheers<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 27 June 2014 14:21, 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi<div><br></div><div>I looked further into this, seems you found a bug.</div><div>In fact we do not support passing strings by reference to a method (for the moment).</div>
<div>I opened an issue on the bugtracker [1], you can register yourself and follow it.</div><div><br></div><div>I found a way to fix this, I just need to implement it in ITK (and see if it does not break the build).</div>
<div>I will work on this during the weekend.</div><div><br></div><div>[1] <a href="https://issues.itk.org/jira/browse/ITK-3285" target="_blank">https://issues.itk.org/jira/browse/ITK-3285</a><br><div><br></div><div><br><div>
<div>Le 25 juin 2014 à 15:45, Michka Popoff a écrit :</div><div><div class="h5"><br><blockquote type="cite"><div style="word-wrap:break-word"><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><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">
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><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>> _____________________________________<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></div></blockquote></div></div></div><br></div></div></div></blockquote></div><br></div>
</blockquote></div><br></div></body></html>