[Insight-users] Problem with saving Image Position value in "z" axis
Alberto
bertorey at gmail.com
Fri Apr 15 12:53:21 EDT 2011
I only test it on this version.
I modify the class itkGDCMImageIO on line 711 replacing this code :
image.SetOrigin(2, 0);
by the following :
if( header.FindDataElement( gdcm::Tag(0x0020, 0x0032 ) )){
const gdcm::DataElement &de = header.GetDataElement( gdcm::Tag(0x0020,
0x0032) );
std::pair<std::string, std::string> s = sf.ToStringPair( de.GetTag() );
std::string value= s.second;
sscanf( value.c_str(), "%lf\\%lf\\%lf", &(m_Origin[0]), &(m_Origin[1]),
&(m_Origin[2]) );
image.SetOrigin(2, m_Origin[2]);
}
and now the Image Patient Position tag is set ok with the correct value of
z-axis. Could this code be a valid patch for the problem?
Thank you.
2011/4/15 Bill Lorensen <bill.lorensen at gmail.com>
> I realize that. I was asking Mical.
>
> Did your code work properly with earlier versions of itk?
>
> Bill
>
> On Fri, Apr 15, 2011 at 12:30 PM, Alberto <bertorey at gmail.com> wrote:
> > The git version of ITK
> >
> > 2011/4/15 Bill Lorensen <bill.lorensen at gmail.com>
> >>
> >> What version of itk are you using?
> >>
> >> On Thu, Apr 14, 2011 at 5:16 AM, Bc. Michal Srna <michal at srna.info>
> wrote:
> >> > Hello,
> >> >
> >> > I have used part of this code to generate MetaDataDictionary:
> >> >
> >> > http://www.itk.org/Wiki/ITK/Examples/DICOM/ResampleDICOM
> >> >
> >> > Everything works, as I need, but I have just one problem in part
> >> > regarding
> >> > saving Image Position (origin) for "z" axis. "x,y" are stored well,
> but
> >> > "z"
> >> > value of Image Position is 0.
> >> >
> >> > Here is that part of the code for saving the Image position:
> >> >
> >> > ImageType::PointType position;
> >> > ImageType::IndexType index;
> >> > index[0] = 0;
> >> > index[1] = 0;
> >> > index[2] = f;
> >> >
> >> > reader->GetOutput()->TransformIndexToPhysicalPoint(index, position);
> >> >
> >> > value.str("");
> >> > value << position[0] << "\\" << position[1] <<
> >> > "\\"
> >> > << position[2];
> >> >
> >> >
> >> > itk::EncapsulateMetaData<std::string>(*dict,"0020|0032", value.str());
> >> > //WHY
> >> > NOT WORKING??
> >> >
> >> > position[2] contains the correct value, but I don't know, why is that
> >> > value
> >> > not saved and instead of that value is stored just 0?
> >> >
> >> > I think I should add also the whole code for generating my
> >> > MetaDataDictionary for see my problem in context.
> >> >
> >> > At first it opens original data, from which I read original meta data.
> >> > Then
> >> > I modify some parts of those meta data in for cycle creating meta data
> >> > for
> >> > each slice.
> >> >
> >> > I confirmed, that original data contains correct value of Image
> Position
> >> > in
> >> > "z" axis. But I need to recalculate that value and store new value.
> >> > Problem
> >> > is, as I told, that this value is not saved and instead of it, there
> is
> >> > just
> >> > 0.
> >> >
> >> > Here is the whole code, spacing[x] is derived from other part of the
> >> > whole
> >> > code, I don't want to copy here:
> >> >
> >> > /*opening original data for getting meta data dictionry for saving it
> >> > into
> >> > output 2D series files*/
> >> > typedef itk::GDCMImageIO ImageIOType;
> >> > typedef itk::GDCMSeriesFileNames NamesGeneratorType;
> >> > typedef itk::ImageSeriesReader< ImageType > ReaderType;
> >> >
> >> > ImageIOType::Pointer gdcmIO = ImageIOType::New();
> >> > ReaderType::Pointer reader = ReaderType::New();
> >> >
> >> > NamesGeneratorType::Pointer namesGenerator =
> >> > NamesGeneratorType::New();
> >> > namesGenerator->SetInputDirectory( StudyFolderName );
> >> > const ReaderType::FileNamesContainer & filenames =
> >> > namesGenerator->GetInputFileNames();
> >> >
> >> > reader->SetImageIO( gdcmIO );
> >> > reader->SetFileNames( filenames );
> >> >
> >> > reader->Update();
> >> >
> >> > /*creating MetaDataDictionary for each slice*/
> >> >
> >> > /*Copy the dictionary from the first image and override
> >> > slice
> >> > specific fields*/
> >> > ReaderType::DictionaryRawPointer inputDictionary =
> >> > (*(reader->GetMetaDataDictionaryArray()))[0];
> >> > ReaderType::DictionaryArrayType dictionaryOutputArray;
> >> >
> >> > /*To keep the new series in the same study as the original
> >> > we
> >> > need to keep the same study UID. But we need new series and frame of
> >> > reference UID's.*/
> >> > #if ITK_VERSION_MAJOR >= 4
> >> > gdcm::UIDGenerator suid;
> >> > std::string seriesUID = suid.Generate();
> >> > gdcm::UIDGenerator fuid;
> >> > std::string frameOfReferenceUID = fuid.Generate();
> >> > #else
> >> > std::string seriesUID = gdcm::Util::CreateUniqueUID(
> >> > gdcmIO->GetUIDPrefix());
> >> > std::string frameOfReferenceUID =
> >> > gdcm::Util::CreateUniqueUID( gdcmIO->GetUIDPrefix());
> >> > #endif
> >> > std::string studyUID;
> >> > std::string sopClassUID;
> >> > itk::ExposeMetaData<std::string>(*inputDictionary,
> >> > "0020|000d", studyUID);
> >> > itk::ExposeMetaData<std::string>(*inputDictionary,
> >> > "0008|0016", sopClassUID);
> >> > gdcmIO->KeepOriginalUIDOn();
> >> >
> >> > for (unsigned int f = 0; f < size[2]; f++)
> >> > {
> >> > // Create a new dictionary for this slice
> >> > ReaderType::DictionaryRawPointer dict = new
> >> > ReaderType::DictionaryType;
> >> >
> >> > // Copy the dictionary from the first slice
> >> > CopyDictionary (*inputDictionary, *dict);
> >> >
> >> > // Set the UID's for the study, series, SOP and
> >> > frame
> >> > of reference
> >> >
> >> > itk::EncapsulateMetaData<std::string>(*dict,"0020|000d", studyUID);
> >> >
> >> > itk::EncapsulateMetaData<std::string>(*dict,"0020|000e", seriesUID);
> >> >
> >> > itk::EncapsulateMetaData<std::string>(*dict,"0020|0052",
> >> > frameOfReferenceUID);
> >> >
> >> > #if ITK_VERSION_MAJOR >= 4
> >> > gdcm::UIDGenerator sopuid;
> >> > std::string sopInstanceUID =
> sopuid.Generate();
> >> > #else
> >> > std::string sopInstanceUID =
> >> > gdcm::Util::CreateUniqueUID( gdcmIO->GetUIDPrefix());
> >> > #endif
> >> >
> >> > itk::EncapsulateMetaData<std::string>(*dict,"0008|0018",
> >> > sopInstanceUID);
> >> >
> >> > itk::EncapsulateMetaData<std::string>(*dict,"0002|0003",
> >> > sopInstanceUID);
> >> >
> >> > // Change fields that are slice specific
> >> > itksys_ios::ostringstream value;
> >> > value.str("");
> >> > value << f + 1;
> >> >
> >> > // Image Number
> >> >
> >> > itk::EncapsulateMetaData<std::string>(*dict,"0020|0013", value.str());
> >> >
> >> > // Series Description - Append new description to
> >> > current series description
> >> > std::string oldSeriesDesc;
> >> >
> >> > itk::ExposeMetaData<std::string>(*inputDictionary,
> >> > "0008|103e", oldSeriesDesc);
> >> >
> >> > value.str("");
> >> > value << oldSeriesDesc
> >> > << spacing[0] << ", "
> >> > << spacing[1] << ", "
> >> > << spacing[2];
> >> >
> >> > // This is an long string and there is a 64
> >> > character
> >> > limit in the standard
> >> > unsigned lengthDesc = value.str().length();
> >> >
> >> > std::string seriesDesc( value.str(), 0,
> >> > lengthDesc > 64 ? 64
> >> > : lengthDesc);
> >> >
> >> > itk::EncapsulateMetaData<std::string>(*dict,"0008|103e", seriesDesc);
> >> >
> >> > // Series Number
> >> > value.str("");
> >> > value << 1001;
> >> >
> >> > itk::EncapsulateMetaData<std::string>(*dict,"0020|0011", value.str());
> >> >
> >> > //Image Position Patient: This is calculated by
> >> > computing the physical coordinate of the first pixel in each slice.
> >> > ImageType::PointType position;
> >> > ImageType::IndexType index;
> >> > index[0] = 0;
> >> > index[1] = 0;
> >> > index[2] = f;
> >> >
> >> > reader->GetOutput()->TransformIndexToPhysicalPoint(index, position);
> >> >
> >> > value.str("");
> >> > value << position[0] << "\\" << position[1] <<
> >> > "\\"
> >> > << position[2];
> >> >
> >> >
> >> > itk::EncapsulateMetaData<std::string>(*dict,"0020|0032", value.str());
> >> > //WHY
> >> > NOT WORKING??
> >> >
> >> > // Slice Location: For now, we store the z
> component
> >> > of
> >> > the Image Position Patient.
> >> > value.str("");
> >> > value << position[2];
> >> >
> >> > itk::EncapsulateMetaData<std::string>(*dict,"0020|1041", value.str());
> >> >
> >> > // Spacing Between Slices
> >> > value.str("");
> >> > value << spacing[2];
> >> >
> >> > itk::EncapsulateMetaData<std::string>(*dict,"0018|0088", value.str());
> >> >
> >> > // Change specific values
> >> > //
> itk::EncapsulateMetaData<std::string>(*dict,
> >> > "0028|0100", "16" );
> >> >
> >> >
> >> > // Save the dictionary
> >> > dictionaryOutputArray.push_back(dict);
> >> > }
> >> >
> >> > Thanks guys in advance...
> >> >
> >> > --
> >> > S pozdravem Bc. Michal Srna
> >> >
> >> > Fotografické portfolio:
> >> > http://michalsrna.cz
> >> >
> >> > _____________________________________
> >> > Powered by www.kitware.com
> >> >
> >> > Visit other Kitware open-source projects at
> >> > http://www.kitware.com/opensource/opensource.html
> >> >
> >> > Kitware offers ITK Training Courses, for more information visit:
> >> > http://www.kitware.com/products/protraining.html
> >> >
> >> > Please keep messages on-topic and check the ITK FAQ at:
> >> > http://www.itk.org/Wiki/ITK_FAQ
> >> >
> >> > Follow this link to subscribe/unsubscribe:
> >> > http://www.itk.org/mailman/listinfo/insight-users
> >> >
> >> >
> >> _____________________________________
> >> Powered by www.kitware.com
> >>
> >> Visit other Kitware open-source projects at
> >> http://www.kitware.com/opensource/opensource.html
> >>
> >> Kitware offers ITK Training Courses, for more information visit:
> >> http://www.kitware.com/products/protraining.html
> >>
> >> Please keep messages on-topic and check the ITK FAQ at:
> >> http://www.itk.org/Wiki/ITK_FAQ
> >>
> >> Follow this link to subscribe/unsubscribe:
> >> http://www.itk.org/mailman/listinfo/insight-users
> >
> >
> > _____________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Kitware offers ITK Training Courses, for more information visit:
> > http://www.kitware.com/products/protraining.html
> >
> > Please keep messages on-topic and check the ITK FAQ at:
> > http://www.itk.org/Wiki/ITK_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.itk.org/mailman/listinfo/insight-users
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110415/d1fdb0c9/attachment-0001.htm>
More information about the Insight-users
mailing list