[Insight-users] Writing DICOM series
Luis Ibanez
luis.ibanez at kitware.com
Sun Apr 18 12:36:06 EDT 2010
Hi Dev,
One of the many Great Things about Open Source
is that you can see how things are implemented. :-)
Open the file:
Insight/Code/IO/itkGDCMImageIO.cxx
Note the command
#if GDCM_MAJOR_VERSION < 2
in line 1318.
and its corresponding #else and #endif in lines
1841 and 2229 respectively.
Then got to lines 1944-1952
else if( key == ITK_Origin )
{
typedef Array< double > DoubleArrayType;
DoubleArrayType originArray;
ExposeMetaData< DoubleArrayType >( dict, key, originArray );
m_Origin[0] = originArray[0];
m_Origin[1] = originArray[1];
m_Origin[2] = originArray[2];
}
and lines 1984-1986:
image.SetOrigin(0, m_Origin[0] );
image.SetOrigin(1, m_Origin[1] );
image.SetOrigin(2, m_Origin[2] );
That will show you that, in summary, when using GDCM 2.0
the position ("origin") of the image, is not taken from the
DICOM tag: 0x0020,0x0032 , but from the image content
specified in
image->GetOrigin().
The behavior that you described in your email:
Using the origin provided by the user
in the tag 0x0020,0x0032)
only happens when you use a GDCM version < 2,
as you can verify in the lines 1473-1492:
// In the case where user specifically set the Image Position (Patient)
either
// directly or indirectly using SetMetaDataDictionaryArray, we should not
try
// to override it's input
if( !header->GetValEntry(0x0020,0x0032 ) )
{
str.str("");
str << m_Origin[0] << "\\" << m_Origin[1] << "\\";
if( m_Origin.size() == 3 )
{
str << m_Origin[2];
}
else // We are coming from the default SeriesWriter which is passing us
a 2D image
// therefore default to a Z position = 0, this will make the image at
least valid
// if not correct
{
str << 0.;
}
header->InsertValEntry(str.str(),0x0020,0x0032); // Image Position
(Patient)
}
These lines above are only used when
#if GDCM_MAJOR_VERSION < 2
Therefore,
The safest way of changing the image origin
is actually by using the:
itkChangeInformationImageFilter
http://www.itk.org/Doxygen/html/classitk_1_1ChangeInformationImageFilter.html
Please note however, that changing the origin of
an image is a very dramatic action, particularly if
you are dealing with DICOM image, and that you
must have a *very strong* justification for doing so.
In general changing the image parameters by hand,
is a dangerous thing to do.
Please let us know if you have other questions.
Enjoy the Freedom to understand
how Software Works :-)
Enjoy Open Source !
Luis
--------------------------------------------------------------------------
On Fri, Apr 16, 2010 at 5:15 AM, dev hurmex <dev at hurmex.fi> wrote:
> Hi,
>
> I use ITK 3.16 + GDCM2.
>
> I write a volume as DICOM series. I set the image position (tag(0020,0032))
> before writing.
> Why the writer (itk::ImageSeriesWriter ) changes it during writing process?
>
> How the image position compute inside ITK or GDCM?
>
> _____________________________________
> 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/20100418/91538ee0/attachment-0001.htm>
More information about the Insight-users
mailing list