The git version of ITK<br><br><div class="gmail_quote">2011/4/15 Bill Lorensen <span dir="ltr">&lt;<a href="mailto:bill.lorensen@gmail.com">bill.lorensen@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

What version of itk are you using?<br>
<div><div></div><div class="h5"><br>
On Thu, Apr 14, 2011 at 5:16 AM, Bc. Michal Srna &lt;<a href="mailto:michal@srna.info">michal@srna.info</a>&gt; wrote:<br>
&gt; Hello,<br>
&gt;<br>
&gt; I have used part of this code to generate MetaDataDictionary:<br>
&gt;<br>
&gt; <a href="http://www.itk.org/Wiki/ITK/Examples/DICOM/ResampleDICOM" target="_blank">http://www.itk.org/Wiki/ITK/Examples/DICOM/ResampleDICOM</a><br>
&gt;<br>
&gt; Everything works, as I need, but I have just one problem in part regarding<br>
&gt; saving Image Position (origin) for &quot;z&quot; axis. &quot;x,y&quot; are stored well, but &quot;z&quot;<br>
&gt; value of Image Position is 0.<br>
&gt;<br>
&gt; Here is that part of the code for saving the Image position:<br>
&gt;<br>
&gt;                         ImageType::PointType position;<br>
&gt;                         ImageType::IndexType index;<br>
&gt;                         index[0] = 0;<br>
&gt;                         index[1] = 0;<br>
&gt;                         index[2] = f;<br>
&gt;<br>
&gt; reader-&gt;GetOutput()-&gt;TransformIndexToPhysicalPoint(index, position);<br>
&gt;<br>
&gt;                         value.str(&quot;&quot;);<br>
&gt;                         value &lt;&lt; position[0] &lt;&lt; &quot;\\&quot; &lt;&lt; position[1] &lt;&lt; &quot;\\&quot;<br>
&gt; &lt;&lt; position[2];<br>
&gt;<br>
&gt;<br>
&gt; itk::EncapsulateMetaData&lt;std::string&gt;(*dict,&quot;0020|0032&quot;, value.str()); //WHY<br>
&gt; NOT WORKING??<br>
&gt;<br>
&gt; position[2] contains the correct value, but I don&#39;t know, why is that value<br>
&gt; not saved and instead of that value is stored just 0?<br>
&gt;<br>
&gt; I think I should add also the whole code for generating my<br>
&gt; MetaDataDictionary for see my problem in context.<br>
&gt;<br>
&gt; At first it opens original data, from which I read original meta data. Then<br>
&gt; I modify some parts of those meta data in for cycle creating meta data for<br>
&gt; each slice.<br>
&gt;<br>
&gt; I confirmed, that original data contains correct value of Image Position in<br>
&gt; &quot;z&quot; axis. But I need to recalculate that value and store new value. Problem<br>
&gt; is, as I told, that this value is not saved and instead of it, there is just<br>
&gt; 0.<br>
&gt;<br>
&gt; Here is the whole code, spacing[x] is derived from other part of the whole<br>
&gt; code, I don&#39;t want to copy here:<br>
&gt;<br>
&gt; /*opening original data for getting meta data dictionry for saving it into<br>
&gt; output 2D series files*/<br>
&gt;             typedef itk::GDCMImageIO ImageIOType;<br>
&gt;             typedef itk::GDCMSeriesFileNames NamesGeneratorType;<br>
&gt;             typedef itk::ImageSeriesReader&lt; ImageType &gt; ReaderType;<br>
&gt;<br>
&gt;             ImageIOType::Pointer gdcmIO = ImageIOType::New();<br>
&gt;             ReaderType::Pointer reader = ReaderType::New();<br>
&gt;<br>
&gt;             NamesGeneratorType::Pointer namesGenerator =<br>
&gt; NamesGeneratorType::New();<br>
&gt;             namesGenerator-&gt;SetInputDirectory( StudyFolderName );<br>
&gt;             const ReaderType::FileNamesContainer &amp; filenames =<br>
&gt; namesGenerator-&gt;GetInputFileNames();<br>
&gt;<br>
&gt;             reader-&gt;SetImageIO( gdcmIO );<br>
&gt;             reader-&gt;SetFileNames( filenames );<br>
&gt;<br>
&gt;             reader-&gt;Update();<br>
&gt;<br>
&gt;         /*creating MetaDataDictionary for each slice*/<br>
&gt;<br>
&gt;             /*Copy the dictionary from the first image and override slice<br>
&gt; specific fields*/<br>
&gt;                 ReaderType::DictionaryRawPointer inputDictionary =<br>
&gt; (*(reader-&gt;GetMetaDataDictionaryArray()))[0];<br>
&gt;                 ReaderType::DictionaryArrayType dictionaryOutputArray;<br>
&gt;<br>
&gt;             /*To keep the new series in the same study as the original we<br>
&gt; need to keep the same study UID. But we need new series and frame of<br>
&gt; reference UID&#39;s.*/<br>
&gt;                 #if ITK_VERSION_MAJOR &gt;= 4<br>
&gt;                   gdcm::UIDGenerator suid;<br>
&gt;                   std::string seriesUID = suid.Generate();<br>
&gt;                   gdcm::UIDGenerator fuid;<br>
&gt;                   std::string frameOfReferenceUID = fuid.Generate();<br>
&gt;                 #else<br>
&gt;                   std::string seriesUID = gdcm::Util::CreateUniqueUID(<br>
&gt; gdcmIO-&gt;GetUIDPrefix());<br>
&gt;                   std::string frameOfReferenceUID =<br>
&gt; gdcm::Util::CreateUniqueUID( gdcmIO-&gt;GetUIDPrefix());<br>
&gt;                 #endif<br>
&gt;                   std::string studyUID;<br>
&gt;                   std::string sopClassUID;<br>
&gt;                   itk::ExposeMetaData&lt;std::string&gt;(*inputDictionary,<br>
&gt; &quot;0020|000d&quot;, studyUID);<br>
&gt;                   itk::ExposeMetaData&lt;std::string&gt;(*inputDictionary,<br>
&gt; &quot;0008|0016&quot;, sopClassUID);<br>
&gt;                   gdcmIO-&gt;KeepOriginalUIDOn();<br>
&gt;<br>
&gt;                 for (unsigned int f = 0; f &lt; size[2]; f++)<br>
&gt;                 {<br>
&gt;                     // Create a new dictionary for this slice<br>
&gt;                         ReaderType::DictionaryRawPointer dict = new<br>
&gt; ReaderType::DictionaryType;<br>
&gt;<br>
&gt;                     // Copy the dictionary from the first slice<br>
&gt;                         CopyDictionary (*inputDictionary, *dict);<br>
&gt;<br>
&gt;                     // Set the UID&#39;s for the study, series, SOP  and frame<br>
&gt; of reference<br>
&gt;<br>
&gt; itk::EncapsulateMetaData&lt;std::string&gt;(*dict,&quot;0020|000d&quot;, studyUID);<br>
&gt;<br>
&gt; itk::EncapsulateMetaData&lt;std::string&gt;(*dict,&quot;0020|000e&quot;, seriesUID);<br>
&gt;<br>
&gt; itk::EncapsulateMetaData&lt;std::string&gt;(*dict,&quot;0020|0052&quot;,<br>
&gt; frameOfReferenceUID);<br>
&gt;<br>
&gt;                     #if ITK_VERSION_MAJOR &gt;= 4<br>
&gt;                         gdcm::UIDGenerator sopuid;<br>
&gt;                         std::string sopInstanceUID = sopuid.Generate();<br>
&gt;                     #else<br>
&gt;                         std::string sopInstanceUID =<br>
&gt; gdcm::Util::CreateUniqueUID( gdcmIO-&gt;GetUIDPrefix());<br>
&gt;                     #endif<br>
&gt;<br>
&gt; itk::EncapsulateMetaData&lt;std::string&gt;(*dict,&quot;0008|0018&quot;, sopInstanceUID);<br>
&gt;<br>
&gt; itk::EncapsulateMetaData&lt;std::string&gt;(*dict,&quot;0002|0003&quot;, sopInstanceUID);<br>
&gt;<br>
&gt;                     // Change fields that are slice specific<br>
&gt;                         itksys_ios::ostringstream value;<br>
&gt;                         value.str(&quot;&quot;);<br>
&gt;                         value &lt;&lt; f + 1;<br>
&gt;<br>
&gt;                     // Image Number<br>
&gt;<br>
&gt; itk::EncapsulateMetaData&lt;std::string&gt;(*dict,&quot;0020|0013&quot;, value.str());<br>
&gt;<br>
&gt;                     // Series Description - Append new description to<br>
&gt; current series description<br>
&gt;                         std::string oldSeriesDesc;<br>
&gt;                         itk::ExposeMetaData&lt;std::string&gt;(*inputDictionary,<br>
&gt; &quot;0008|103e&quot;, oldSeriesDesc);<br>
&gt;<br>
&gt;                         value.str(&quot;&quot;);<br>
&gt;                         value &lt;&lt; oldSeriesDesc<br>
&gt;                               &lt;&lt; spacing[0] &lt;&lt; &quot;, &quot;<br>
&gt;                               &lt;&lt; spacing[1] &lt;&lt; &quot;, &quot;<br>
&gt;                               &lt;&lt; spacing[2];<br>
&gt;<br>
&gt;                     // This is an long string and there is a 64 character<br>
&gt; limit in the standard<br>
&gt;                         unsigned lengthDesc = value.str().length();<br>
&gt;<br>
&gt;                         std::string seriesDesc( value.str(), 0,<br>
&gt;                                                 lengthDesc &gt; 64 ? 64<br>
&gt;                                                 : lengthDesc);<br>
&gt;<br>
&gt; itk::EncapsulateMetaData&lt;std::string&gt;(*dict,&quot;0008|103e&quot;, seriesDesc);<br>
&gt;<br>
&gt;                     // Series Number<br>
&gt;                         value.str(&quot;&quot;);<br>
&gt;                         value &lt;&lt; 1001;<br>
&gt;<br>
&gt; itk::EncapsulateMetaData&lt;std::string&gt;(*dict,&quot;0020|0011&quot;, value.str());<br>
&gt;<br>
&gt;                     //Image Position Patient: This is calculated by<br>
&gt; computing the physical coordinate of the first pixel in each slice.<br>
&gt;                         ImageType::PointType position;<br>
&gt;                         ImageType::IndexType index;<br>
&gt;                         index[0] = 0;<br>
&gt;                         index[1] = 0;<br>
&gt;                         index[2] = f;<br>
&gt;<br>
&gt; reader-&gt;GetOutput()-&gt;TransformIndexToPhysicalPoint(index, position);<br>
&gt;<br>
&gt;                         value.str(&quot;&quot;);<br>
&gt;                         value &lt;&lt; position[0] &lt;&lt; &quot;\\&quot; &lt;&lt; position[1] &lt;&lt; &quot;\\&quot;<br>
&gt; &lt;&lt; position[2];<br>
&gt;<br>
&gt;<br>
&gt; itk::EncapsulateMetaData&lt;std::string&gt;(*dict,&quot;0020|0032&quot;, value.str()); //WHY<br>
&gt; NOT WORKING??<br>
&gt;<br>
&gt;                     // Slice Location: For now, we store the z component of<br>
&gt; the Image Position Patient.<br>
&gt;                         value.str(&quot;&quot;);<br>
&gt;                         value &lt;&lt; position[2];<br>
&gt;<br>
&gt; itk::EncapsulateMetaData&lt;std::string&gt;(*dict,&quot;0020|1041&quot;, value.str());<br>
&gt;<br>
&gt;                     // Spacing Between Slices<br>
&gt;                         value.str(&quot;&quot;);<br>
&gt;                         value &lt;&lt; spacing[2];<br>
&gt;<br>
&gt; itk::EncapsulateMetaData&lt;std::string&gt;(*dict,&quot;0018|0088&quot;, value.str());<br>
&gt;<br>
&gt;                     // Change specific values<br>
&gt;                         //  itk::EncapsulateMetaData&lt;std::string&gt;(*dict,<br>
&gt; &quot;0028|0100&quot;, &quot;16&quot; );<br>
&gt;<br>
&gt;<br>
&gt;                     // Save the dictionary<br>
&gt;                         dictionaryOutputArray.push_back(dict);<br>
&gt;                   }<br>
&gt;<br>
&gt; Thanks guys in advance...<br>
&gt;<br>
&gt; --<br>
&gt; S pozdravem Bc. Michal Srna<br>
&gt;<br>
&gt; Fotografické portfolio:<br>
&gt; <a href="http://michalsrna.cz" target="_blank">http://michalsrna.cz</a><br>
&gt;<br>
</div></div><div><div></div><div class="h5">&gt; _____________________________________<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; Visit other Kitware open-source projects at<br>
&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;<br>
&gt; Kitware offers ITK Training Courses, for more information visit:<br>
&gt; <a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
&gt;<br>
&gt; Please keep messages on-topic and check the ITK FAQ at:<br>
&gt; <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
&gt;<br>
&gt;<br>
_____________________________________<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.html" target="_blank">http://www.kitware.com/products/protraining.html</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://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</div></div></blockquote></div><br>