<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> <deformafieldType> 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 <fstream><br><br><br><br>int main( int argc, char *argv[] )<br>{<br> if( argc < 4 )<br> {<br> std::cerr << "Missing Parameters " << std::endl;<br> std::cerr << "Usage: " << argv[0];<br> std::cerr << " fixedImagefile movingImageFile deformField.vtk<br> ";<br> std::cerr << " outputImageFile " << 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< PixelType, Dimension > FixedImageType;<br> typedef itk::ImageFileReader< FixedImageType ><br> FixedImageReaderType;<br> FixedImageReaderType::Pointer fixedImageReader =<br> FixedImageReaderType::New();<br>
fixedImageReader->SetFileName( argv[1] );<br><br> <br> typedef itk::Image< PixelType, Dimension > MovingImageType;<br> typedef itk::ImageFileReader< MovingImageType ><br> MovingImageReaderType;<br> MovingImageReaderType::Pointer movingImageReader =<br> MovingImageReaderType::New();<br> movingImageReader->SetFileName( argv[2] );<br><br> typedef itk::Vector< float, Dimension > VectorPixelType;<br> typedef itk::Image< VectorPixelType, Dimension ><br> DeformationFieldType;<br><br> typedef itk::ImageFileReader< DeformationFieldType ><br> FieldReaderType;<br> FieldReaderType::Pointer fieldReader = FieldReaderType::New();<br><br> fieldReader->SetFileName( argv[3] );<br><br> <br> try {<br><br> fieldReader->Update();<br> }<br><br> catch ( itk::ExceptionObject & err ) <br> {<br> std::cerr << "ExceptionObject caught !" << std::endl; <br> std::cerr << err <<
std::endl; <br> return -1;<br> } <br><br><br> <br> typedef itk::WarpImageFilter<MovingImageType,<br> MovingImageType,DeformationFieldType > WarperType;<br> typedef itk::LinearInterpolateImageFunction<MovingImageType, double<br> > InterpolatorType;<br> WarperType::Pointer warper = WarperType::New();<br> InterpolatorType::Pointer interpolator = InterpolatorType::New();<br> FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput();<br><br> <br> warper->SetInput( movingImageReader->GetOutput() );<br> warper->SetInterpolator( interpolator );<br> warper->SetOutputSpacing( fixedImage->GetSpacing() );<br> warper->SetOutputOrigin( fixedImage->GetOrigin() );<br><br> warper->SetDeformationField( fieldReader->GetOutput() ); <br><br> <br> typedef unsigned char OutputPixelType;<br> typedef itk::Image< OutputPixelType, Dimension > OutputImageType;<br> typedef
itk::CastImageFilter< <br> MovingImageType,<br> OutputImageType > CastFilterType;<br> typedef itk::ImageFileWriter< OutputImageType > WriterType;<br><br> <br> WriterType::Pointer writer = WriterType::New();<br> CastFilterType::Pointer caster = CastFilterType::New();<br><br> writer->SetFileName( argv[4] );<br><br> <br> caster->SetInput( warper->GetOutput() );<br> writer->SetInput( caster->GetOutput() );<br> writer->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 <eryanvtk@yahoo.com><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: <<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>><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> <deformafieldType> 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 <fstream><br><br><br><br>int main( int argc, char *argv[] )<br>{<br> if( argc < 4 )<br> {<br> std::cerr << "Missing Parameters " << std::endl;<br> std::cerr << "Usage: " << argv[0];<br> std::cerr << " fixedImagefile movingImageFile deformField.vtk<br> ";<br> std::cerr << " outputImageFile " << 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< PixelType, Dimension > FixedImageType;<br> typedef itk::ImageFileReader< FixedImageType
><br> FixedImageReaderType;<br> FixedImageReaderType::Pointer fixedImageReader =<br> FixedImageReaderType::New();<br> fixedImageReader->SetFileName( argv[1] );<br><br> <br> typedef itk::Image< PixelType, Dimension > MovingImageType;<br> typedef itk::ImageFileReader< MovingImageType ><br> MovingImageReaderType;<br> MovingImageReaderType::Pointer movingImageReader =<br> MovingImageReaderType::New();<br> movingImageReader->SetFileName( argv[2] );<br><br> typedef itk::Vector< float, Dimension > VectorPixelType;<br> typedef itk::Image< VectorPixelType, Dimension ><br> DeformationFieldType;<br><br> typedef itk::ImageFileReader< DeformationFieldType ><br> FieldReaderType;<br> FieldReaderType::Pointer fieldReader = FieldReaderType::New();<br><br> fieldReader->SetFileName( argv[3] );<br><br> <br> try {<br><br> fieldReader->Update();<br> }<br><br> catch ( itk::ExceptionObject &
err ) <br> {<br> std::cerr << "ExceptionObject caught !" << std::endl; <br> std::cerr << err << std::endl; <br> return -1;<br> } <br><br><br> <br> typedef itk::WarpImageFilter<MovingImageType,<br> MovingImageType,DeformationFieldType > WarperType;<br> typedef itk::LinearInterpolateImageFunction<MovingImageType, double<br> > InterpolatorType;<br> WarperType::Pointer warper = WarperType::New();<br> InterpolatorType::Pointer interpolator = InterpolatorType::New();<br> FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput();<br><br> <br> warper->SetInput( movingImageReader->GetOutput() );<br> warper->SetInterpolator( interpolator );<br> warper->SetOutputSpacing( fixedImage->GetSpacing() );<br> warper->SetOutputOrigin( fixedImage->GetOrigin() );<br><br> warper->SetDeformationField( fieldReader->GetOutput() ); <br><br> <br> typedef unsigned
char OutputPixelType;<br> typedef itk::Image< OutputPixelType, Dimension > OutputImageType;<br> typedef itk::CastImageFilter< <br> MovingImageType,<br> OutputImageType > CastFilterType;<br> typedef itk::ImageFileWriter< OutputImageType > WriterType;<br><br> <br> WriterType::Pointer writer = WriterType::New();<br> CastFilterType::Pointer caster = CastFilterType::New();<br><br> writer->SetFileName( argv[4] );<br><br> <br> caster->SetInput( warper->GetOutput() );<br> writer->SetInput( caster->GetOutput() );<br> writer->Update();<br><br> <br> return 0;<br>}</tt></tt></pre><br><br><b><i>Luis Ibanez <luis.ibanez@kitware.com></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>> Hi Luis,<br>> <br>> Thank you again for your reply. With regard to " Yes, the Patient <br>> position is the source of the data for the<br>> image origin values" in your reply, how does -255, -255, -30 make sense <br>> ? I'm not sure I understand the logic behind the "Image Patient <br>> Position" tag in a dicom file (0020 - 0032 bytes) .<br>> The IPP in my dicom file is listed as -255, -255, -33. Unless the images <br>> are centered, should these
values be (0, 0, 0) for the first slice ?<br>> <br>> Emma<br>> <br>> <br>> Could you point me to some references if there is a lengthy explanation <br>> for this ?<br>> <br>> <br>> <br>> Question 1:<br>> <br>> When the Similarity3DTransform gets a negative value in the Scale<br>> parameter, that performs a reflection of the space on the origin<br>> of coordinates.... not a good thing at all, particularly in medical<br>> images.<br>> <br>> The scale shouldn't approach a zero value either...<br>> <br>> This however, is possible when you use an optimizer that assumes<br>> that the parameters of the transform are in a Vector space, as<br>> most of the GradientDescent optimizers do.<br>> <br>> <br>> In practice you could have prevented the scale from deforming that<br>> far by setting proper values in the parameter scaling array that<br>> you pass to the optimizer. The purpose of this array is to
let<br>> the optimizer know that we don't expect big changes to occur in<br>> the Scale parameter of Transform.<br>> <br>> <br>> <br>> Question 2:<br>> <br>> You should only need a Similarity transform is you are registering<br>> images from different patients, that will naturally have slightly<br>> different organ sizes. Note however that the size variability of<br>> human specimens is not as large as to need scales smaller than 0.5<br>> or larger than 2.0.<br>> <br>> If you are registering two different patients, then, in addition<br>> to having the origin & spacing taken into account, you may also<br>> need this type of scaling in space.<br>> <br>> <br>> Question 3:<br>> <br>> Resampling will take the image spacing into account. You just<br>> need to make sure that the spacing is set correctly in the images.<br>> Note that the resampling also use the transform anyways.<br>> <br>> <br>>
Question 4:<br>> <br>> No, you don't need to manually compensate for the resolution.<br>> ITK already takes the pixel spacing into account. All the<br>> process of image registration is done in physical coordinates.<br>> <br>> <br>> Question 5:<br>> <br>> Yes, the Patient position is the source of the data for the<br>> image origin values.<br>> <br>> <br>> <br>> <br>> Regards,<br>> <br>> <br>> Luis<br>> <br>> <br>> <br>> -----------------<br>> Emma Ryan wrote:<br>> > Hi,<br>> ><br>> > I am using the itk Similarity3DTranform to obtain a registration<br>> > between two volumes.<br>> > Dataset1 : 512 x 512 x 30 (Resolution = 0.684 x 0.684 x 1.0) : Image<br>> > Patient Position : -175, -175, 125 (from dicom header)<br>> > Dataset2: 512 x 512 x 30 (Resolution = 1.0 x 1.0 x 1.0 ) : Image Patient<br>> > Position: -255, -255, 101 (from dicom
header)<br>> ><br>> > Both are of the same modality (CT).<br>> ><br>> > I have a few questions.<br>> ><br>> > 1. How does one interpret the scale value of (-0.00008). What does<br>> > negative mean ? Division ?<br>> ><br>> > 2. Prior to registration I mention the size, origin and spacing for both<br>> > the fixed and moving volumes. At resampling, the moving volume are<br>> > resampled to match the spacing and origin of the fixed volume. So should<br>> > I care to include the scale transform in my registration/optimization<br>> > parameters ?<br>> ><br>> > 3. Does resampling take care of the resolution difference ?<br>> ><br>> > 4. Is it necessary that I set the initial scaling to 1.428 to compensate<br>> > for the resolution ?<br>> ><br>> > 5. Dicom images have Image Patient Postion tag. Is this the information<br>> > that
goes into the "Origin" variable ? If not, where do I get the<br>> > image origin information ?<br>> ><br>> > I have read a lot of literature on resampling and all the pdfs and ppts<br>> > on ITK, but I fail to understand these.<br>> ><br>> > Please help !<br>> ><br>> > Emma<br>> ><br>> > ------------------------------------------------------------------------<br>> > Get the Yahoo! toolbar and be alerted to new email<br>> > <br>> <http: //us.rd.yahoo.com/evt="48225/*http://new.toolbar.yahoo.com/toolbar/features/mail/index.php">wherever <br>> <http: //us.rd.yahoo.com/evt="48225/*http://new.toolbar.yahoo.com/toolbar/features/mail/index.php%3Ewherever"> <br>> <br>> > you're surfing.<br>> ><br>> ><br>> > ------------------------------------------------------------------------<br>> ><br>> >
_______________________________________________<br>> > Insight-users mailing list<br>> > Insight-users@itk.org<br>> > http://www.itk.org/mailman/listinfo/insight-users<br>> <br>> <br>> ------------------------------------------------------------------------<br>> Got a little couch potato?<br>> Check out fun summer activities for kids. <br>> <http: //us.rd.yahoo.com/evt="48248/*http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities+for+kids&cs=bz"><br></http:></http:></http:></blockquote><br><p> 
<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>