<pre><tt><tt>Hi,<br><br>  I forgot to put an appropriate heading, so wasn't sure if people were gonne read my email.<br>Hence the repeat.<br><br>Thanks,<br>Emma<br><br><br>Hi,<br> <br>  I am trying to read in a 3D deformationField.vtk file and apply it to<br> a 3D image. To read the deformation field, I use ImageFileReader<br> &lt;deformafieldType&gt;  and then connect the output of this to the warper.<br><br>The code for this is available below.  It seems to take forever to read<br> the deformation field file.  Even after 2 hours, the reading is not<br> complete. What is going on ?  Any clues ?<br><br>Thanks,<br>Emma<br><br><br>#if defined(_MSC_VER)<br>#pragma warning ( disable : 4786 )<br>#endif<br><br>#include "itkImageFileReader.h" <br>#include "itkImageFileWriter.h" <br><br>#include "itkImageRegionIterator.h"<br><br><br>#include "itkCastImageFilter.h"<br>#include "itkWarpImageFilter.h"<br>#include "itkLinearInterpolateImageFunction.h"<br><br>#include
 "itkSquaredDifferenceImageFilter.h"<br>#include "itkCheckerBoardImageFilter.h"<br>#include "itkTimeProbe.h"       <br><br>#include "itkImageRegionIteratorWithIndex.h"<br>#include "itkPointSet.h"<br>#include &lt;fstream&gt;<br><br><br><br>int main( int argc, char *argv[] )<br>{<br>    if( argc &lt; 4 )<br>    {<br>        std::cerr &lt;&lt; "Missing Parameters " &lt;&lt; std::endl;<br>        std::cerr &lt;&lt; "Usage: " &lt;&lt; argv[0];<br>        std::cerr &lt;&lt; " fixedImagefile movingImageFile deformField.vtk<br> ";<br>        std::cerr &lt;&lt; " outputImageFile " &lt;&lt; std::endl;<br>        return 1;<br>    }<br><br>    <br>    const unsigned int Dimension = 3;<br>    typedef unsigned char PixelType;<br><br><br>    typedef itk::Image&lt; PixelType, Dimension &gt;  FixedImageType;<br>    typedef itk::ImageFileReader&lt; FixedImageType &gt;<br> FixedImageReaderType;<br>    FixedImageReaderType::Pointer fixedImageReader =<br> FixedImageReaderType::New();<br>   
 fixedImageReader-&gt;SetFileName( argv[1] );<br><br>    <br>    typedef itk::Image&lt; PixelType, Dimension &gt;  MovingImageType;<br>    typedef itk::ImageFileReader&lt; MovingImageType &gt;<br> MovingImageReaderType;<br>    MovingImageReaderType::Pointer movingImageReader =<br> MovingImageReaderType::New();<br>    movingImageReader-&gt;SetFileName( argv[2] );<br><br>        typedef itk::Vector&lt; float, Dimension &gt;    VectorPixelType;<br>    typedef itk::Image&lt;  VectorPixelType, Dimension &gt;<br> DeformationFieldType;<br><br>    typedef itk::ImageFileReader&lt; DeformationFieldType &gt;<br>  FieldReaderType;<br>    FieldReaderType::Pointer fieldReader = FieldReaderType::New();<br><br>    fieldReader-&gt;SetFileName( argv[3] );<br><br>   <br>   try {<br><br>    fieldReader-&gt;Update();<br>   }<br><br>   catch ( itk::ExceptionObject &amp; err ) <br>   {<br>    std::cerr &lt;&lt; "ExceptionObject caught !" &lt;&lt; std::endl; <br>    std::cerr &lt;&lt; err &lt;&lt;
 std::endl; <br>    return -1;<br>    } <br><br><br>    <br>    typedef itk::WarpImageFilter&lt;MovingImageType,<br> MovingImageType,DeformationFieldType  &gt;     WarperType;<br>    typedef itk::LinearInterpolateImageFunction&lt;MovingImageType, double<br>  &gt;  InterpolatorType;<br>    WarperType::Pointer warper = WarperType::New();<br>    InterpolatorType::Pointer interpolator = InterpolatorType::New();<br>    FixedImageType::Pointer fixedImage = fixedImageReader-&gt;GetOutput();<br><br>   <br>    warper-&gt;SetInput( movingImageReader-&gt;GetOutput() );<br>    warper-&gt;SetInterpolator( interpolator );<br>    warper-&gt;SetOutputSpacing( fixedImage-&gt;GetSpacing() );<br>    warper-&gt;SetOutputOrigin( fixedImage-&gt;GetOrigin() );<br><br>    warper-&gt;SetDeformationField( fieldReader-&gt;GetOutput() ); <br><br>  <br>    typedef  unsigned char  OutputPixelType;<br>    typedef itk::Image&lt; OutputPixelType, Dimension &gt; OutputImageType;<br>    typedef
 itk::CastImageFilter&lt; <br>        MovingImageType,<br>        OutputImageType &gt; CastFilterType;<br>    typedef itk::ImageFileWriter&lt; OutputImageType &gt;  WriterType;<br><br>  <br>    WriterType::Pointer      writer =  WriterType::New();<br>    CastFilterType::Pointer  caster =  CastFilterType::New();<br><br>    writer-&gt;SetFileName( argv[4] );<br><br>    <br>    caster-&gt;SetInput( warper-&gt;GetOutput() );<br>    writer-&gt;SetInput( caster-&gt;GetOutput()   );<br>    writer-&gt;Update();<br><br>   <br>    return 0;<br>}<br><br><br><br><br><br><br>    <br>  ____________________________________________________________________________________<br>Be a better friend, newshound, and <br>know-it-all with <span style="border-bottom: 1px dashed rgb(0, 102, 204); cursor: pointer;" class="yshortcuts" id="lw_1203605774_11">Yahoo! Mobile</span>.  Try it now.<br>  <a target="_blank" href="http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ"><span class="yshortcuts"
 id="lw_1203605774_12">http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ</span></a> <br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL:<br> <a target="_blank" href="http://public.kitware.com/pipermail/insight-users/attachments/20080221/ae444f83/attachment-0001.html"><span class="yshortcuts" id="lw_1203605774_13">http://public.kitware.com/pipermail/insight-users/attachments/20080221/ae444f83/attachment-0001.html</span></a><br><br>------------------------------<br><br>Message: 3<br>Date: Thu, 21 Feb 2008 00:41:31 -0800 (PST)<br>From: Emma Ryan &lt;eryanvtk@yahoo.com&gt;<br>Subject: [Insight-users] Is it silly to attempt this ?<br>To: <span style="border-bottom: 1px dashed rgb(0, 102, 204); cursor: pointer;" class="yshortcuts" id="lw_1203605774_14">insight-users@itk.org</span><br>Cc: <span style="border-bottom: 1px dashed rgb(0, 102, 204); cursor: pointer;" class="yshortcuts"
 id="lw_1203605774_15">insight-users@itk.org</span><br>Message-ID: &lt;<span style="border-bottom: 1px dashed rgb(0, 102, 204); cursor: pointer;" class="yshortcuts" id="lw_1203605774_16">625726.500.qm@web57908.mail.re3.yahoo.com</span>&gt;<br>Content-Type: text/plain; charset="us-ascii"<br><br>Hi,<br> <br>  I am trying to read in a 3D deformationField.vtk file and apply it to<br> a 3D image. To read the deformation field, I use ImageFileReader<br> &lt;deformafieldType&gt;  and then connect the output of this to the warper.<br><br>The code for this is available below.  It seems to take forever to read<br> the deformation field file.  Even after 2 hours, the reading is not<br> complete. What is going on ?  Any clues ?<br><br>Thanks,<br>Emma<br><br><br>#if defined(_MSC_VER)<br>#pragma warning ( disable : 4786 )<br>#endif<br><br>#include "itkImageFileReader.h" <br>#include "itkImageFileWriter.h" <br><br>#include "itkImageRegionIterator.h"<br><br><br>#include
 "itkCastImageFilter.h"<br>#include "itkWarpImageFilter.h"<br>#include "itkLinearInterpolateImageFunction.h"<br><br>#include "itkSquaredDifferenceImageFilter.h"<br>#include "itkCheckerBoardImageFilter.h"<br>#include "itkTimeProbe.h"       <br><br>#include "itkImageRegionIteratorWithIndex.h"<br>#include "itkPointSet.h"<br>#include &lt;fstream&gt;<br><br><br><br>int main( int argc, char *argv[] )<br>{<br>    if( argc &lt; 4 )<br>    {<br>        std::cerr &lt;&lt; "Missing Parameters " &lt;&lt; std::endl;<br>        std::cerr &lt;&lt; "Usage: " &lt;&lt; argv[0];<br>        std::cerr &lt;&lt; " fixedImagefile movingImageFile deformField.vtk<br> ";<br>        std::cerr &lt;&lt; " outputImageFile " &lt;&lt; std::endl;<br>        return 1;<br>    }<br><br>    <br>    const unsigned int Dimension = 3;<br>    typedef unsigned char PixelType;<br><br><br>    typedef itk::Image&lt; PixelType, Dimension &gt;  FixedImageType;<br>    typedef itk::ImageFileReader&lt; FixedImageType
 &gt;<br> FixedImageReaderType;<br>    FixedImageReaderType::Pointer fixedImageReader =<br> FixedImageReaderType::New();<br>    fixedImageReader-&gt;SetFileName( argv[1] );<br><br>    <br>    typedef itk::Image&lt; PixelType, Dimension &gt;  MovingImageType;<br>    typedef itk::ImageFileReader&lt; MovingImageType &gt;<br> MovingImageReaderType;<br>    MovingImageReaderType::Pointer movingImageReader =<br> MovingImageReaderType::New();<br>    movingImageReader-&gt;SetFileName( argv[2] );<br><br>        typedef itk::Vector&lt; float, Dimension &gt;    VectorPixelType;<br>    typedef itk::Image&lt;  VectorPixelType, Dimension &gt;<br> DeformationFieldType;<br><br>    typedef itk::ImageFileReader&lt; DeformationFieldType &gt;<br>  FieldReaderType;<br>    FieldReaderType::Pointer fieldReader = FieldReaderType::New();<br><br>    fieldReader-&gt;SetFileName( argv[3] );<br><br>   <br>   try {<br><br>    fieldReader-&gt;Update();<br>   }<br><br>   catch ( itk::ExceptionObject &amp;
 err ) <br>   {<br>    std::cerr &lt;&lt; "ExceptionObject caught !" &lt;&lt; std::endl; <br>    std::cerr &lt;&lt; err &lt;&lt; std::endl; <br>    return -1;<br>    } <br><br><br>    <br>    typedef itk::WarpImageFilter&lt;MovingImageType,<br> MovingImageType,DeformationFieldType  &gt;     WarperType;<br>    typedef itk::LinearInterpolateImageFunction&lt;MovingImageType, double<br>  &gt;  InterpolatorType;<br>    WarperType::Pointer warper = WarperType::New();<br>    InterpolatorType::Pointer interpolator = InterpolatorType::New();<br>    FixedImageType::Pointer fixedImage = fixedImageReader-&gt;GetOutput();<br><br>   <br>    warper-&gt;SetInput( movingImageReader-&gt;GetOutput() );<br>    warper-&gt;SetInterpolator( interpolator );<br>    warper-&gt;SetOutputSpacing( fixedImage-&gt;GetSpacing() );<br>    warper-&gt;SetOutputOrigin( fixedImage-&gt;GetOrigin() );<br><br>    warper-&gt;SetDeformationField( fieldReader-&gt;GetOutput() ); <br><br>  <br>    typedef  unsigned
 char  OutputPixelType;<br>    typedef itk::Image&lt; OutputPixelType, Dimension &gt; OutputImageType;<br>    typedef itk::CastImageFilter&lt; <br>        MovingImageType,<br>        OutputImageType &gt; CastFilterType;<br>    typedef itk::ImageFileWriter&lt; OutputImageType &gt;  WriterType;<br><br>  <br>    WriterType::Pointer      writer =  WriterType::New();<br>    CastFilterType::Pointer  caster =  CastFilterType::New();<br><br>    writer-&gt;SetFileName( argv[4] );<br><br>    <br>    caster-&gt;SetInput( warper-&gt;GetOutput() );<br>    writer-&gt;SetInput( caster-&gt;GetOutput()   );<br>    writer-&gt;Update();<br><br>   <br>    return 0;<br>}</tt></tt></pre><br><br><b><i>Luis Ibanez &lt;luis.ibanez@kitware.com&gt;</i></b> wrote:<blockquote class="replbq" style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"> <br>Hi Emma,<br><br>    The origin coordinate do not have to be 0,0,0.<br><br>In fact, the reason for storing the origin in the
 DICOM<br>header is that the values are different from (0,0,0).<br><br>In general the values are reported relative to some origin<br>of coordinates in the scanner itself. Therefore they can<br>be positive or negative and they can easily reach several<br>centimeters in magnitude.<br><br>Note that the origin is measured in physical units.<br>Typically millimeters in a CT scanner. Not in pixels.<br><br><br>     Regards<br><br><br>        Luis<br><br><br>------------------------<br>Emma Ryan wrote:<br>&gt; Hi Luis,<br>&gt; <br>&gt;   Thank you again for your reply. With regard to " Yes, the Patient <br>&gt; position is the source of the data for the<br>&gt; image origin values" in your reply, how does -255, -255, -30 make sense <br>&gt; ? I'm not sure I understand the logic behind the "Image Patient <br>&gt; Position" tag in a dicom file (0020 - 0032 bytes) .<br>&gt; The IPP in my dicom file is listed as -255, -255, -33. Unless the images <br>&gt; are centered, should these
 values be (0, 0, 0) for the first slice ?<br>&gt; <br>&gt; Emma<br>&gt; <br>&gt; <br>&gt; Could you point me to some references if there is a lengthy explanation <br>&gt; for this ?<br>&gt; <br>&gt; <br>&gt; <br>&gt; Question 1:<br>&gt; <br>&gt; When the Similarity3DTransform gets a negative value in the Scale<br>&gt; parameter, that performs a reflection of the space on the origin<br>&gt; of coordinates.... not a good thing at all, particularly in medical<br>&gt; images.<br>&gt; <br>&gt; The scale shouldn't approach a zero value either...<br>&gt; <br>&gt; This however, is possible when you use an optimizer that assumes<br>&gt; that the parameters of the transform are in a Vector space, as<br>&gt; most of the GradientDescent optimizers do.<br>&gt; <br>&gt; <br>&gt; In practice you could have prevented the scale from deforming that<br>&gt; far by setting proper values in the parameter scaling array that<br>&gt; you pass to the optimizer. The purpose of this array is to
 let<br>&gt; the optimizer know that we don't expect big changes to occur in<br>&gt; the Scale parameter of Transform.<br>&gt; <br>&gt; <br>&gt; <br>&gt; Question 2:<br>&gt; <br>&gt; You should only need a Similarity transform is you are registering<br>&gt; images from different patients, that will naturally have slightly<br>&gt; different organ sizes. Note however that the size variability of<br>&gt; human specimens is not as large as to need scales smaller than 0.5<br>&gt; or larger than 2.0.<br>&gt; <br>&gt; If you are registering two different patients, then, in addition<br>&gt; to having the origin &amp; spacing taken into account, you may also<br>&gt; need this type of scaling in space.<br>&gt; <br>&gt; <br>&gt; Question 3:<br>&gt; <br>&gt; Resampling will take the image spacing into account. You just<br>&gt; need to make sure that the spacing is set correctly in the images.<br>&gt; Note that the resampling also use the transform anyways.<br>&gt; <br>&gt; <br>&gt;
 Question 4:<br>&gt; <br>&gt; No, you don't need to manually compensate for the resolution.<br>&gt; ITK already takes the pixel spacing into account. All the<br>&gt; process of image registration is done in physical coordinates.<br>&gt; <br>&gt; <br>&gt; Question 5:<br>&gt; <br>&gt; Yes, the Patient position is the source of the data for the<br>&gt; image origin values.<br>&gt; <br>&gt; <br>&gt; <br>&gt; <br>&gt;     Regards,<br>&gt; <br>&gt; <br>&gt;        Luis<br>&gt; <br>&gt; <br>&gt; <br>&gt; -----------------<br>&gt; Emma Ryan wrote:<br>&gt;  &gt; Hi,<br>&gt;  &gt;<br>&gt;  &gt;   I am using the itk Similarity3DTranform to obtain a registration<br>&gt;  &gt; between two volumes.<br>&gt;  &gt; Dataset1 : 512 x 512 x 30 (Resolution = 0.684 x 0.684 x 1.0) :  Image<br>&gt;  &gt; Patient Position : -175, -175, 125 (from dicom header)<br>&gt;  &gt; Dataset2: 512 x 512 x 30 (Resolution = 1.0 x 1.0 x 1.0 ) : Image Patient<br>&gt;  &gt; Position: -255, -255, 101 (from dicom
 header)<br>&gt;  &gt;<br>&gt;  &gt; Both are of the same modality (CT).<br>&gt;  &gt;<br>&gt;  &gt; I have a few questions.<br>&gt;  &gt;<br>&gt;  &gt; 1. How does one interpret the scale value of  (-0.00008). What does<br>&gt;  &gt; negative mean ?  Division ?<br>&gt;  &gt;<br>&gt;  &gt; 2. Prior to registration I mention the size, origin and spacing for both<br>&gt;  &gt; the fixed and moving volumes. At resampling, the moving volume are<br>&gt;  &gt; resampled to match the spacing and origin of the fixed volume. So should<br>&gt;  &gt; I care to include the scale transform in my registration/optimization<br>&gt;  &gt; parameters ?<br>&gt;  &gt;<br>&gt;  &gt; 3. Does resampling take care of the resolution difference ?<br>&gt;  &gt;<br>&gt;  &gt; 4. Is it necessary that I set the initial scaling to 1.428 to compensate<br>&gt;  &gt; for the resolution ?<br>&gt;  &gt;<br>&gt;  &gt; 5. Dicom images have Image Patient Postion tag. Is this the information<br>&gt;  &gt; that
 goes into the  "Origin" variable ?  If not, where do I get the<br>&gt;  &gt; image origin information ?<br>&gt;  &gt;<br>&gt;  &gt; I have read a lot of literature on resampling and all the pdfs and ppts<br>&gt;  &gt; on ITK, but I fail to understand these.<br>&gt;  &gt;<br>&gt;  &gt; Please help !<br>&gt;  &gt;<br>&gt;  &gt; Emma<br>&gt;  &gt;<br>&gt;  &gt; ------------------------------------------------------------------------<br>&gt;  &gt; Get the Yahoo! toolbar and be alerted to new email<br>&gt;  &gt; <br>&gt; <http: //us.rd.yahoo.com/evt="48225/*http://new.toolbar.yahoo.com/toolbar/features/mail/index.php">wherever <br>&gt; <http: //us.rd.yahoo.com/evt="48225/*http://new.toolbar.yahoo.com/toolbar/features/mail/index.php%3Ewherever"> <br>&gt; <br>&gt;  &gt; you're surfing.<br>&gt;  &gt;<br>&gt;  &gt;<br>&gt;  &gt; ------------------------------------------------------------------------<br>&gt;  &gt;<br>&gt;  &gt;
 _______________________________________________<br>&gt;  &gt; Insight-users mailing list<br>&gt;  &gt; Insight-users@itk.org<br>&gt;  &gt; http://www.itk.org/mailman/listinfo/insight-users<br>&gt; <br>&gt; <br>&gt; ------------------------------------------------------------------------<br>&gt; Got a little couch potato?<br>&gt; Check out fun summer activities for kids. <br>&gt; <http: //us.rd.yahoo.com/evt="48248/*http://search.yahoo.com/search?fr=oni_on_mail&amp;p=summer+activities+for+kids&amp;cs=bz"><br></http:></http:></http:></blockquote><br><p>&#32;
      <hr size=1>Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile. <a href="http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ "> Try it now.</a>