<br>Of the potential problems mentioned, the most obvious is getting the data oriented roughly, so I'm trying to do that first. I'm using ResampleImageFilter4.cxx, modified for 3D rotation. Input and output is mhd, unsigned shorts. <br>
<br>When I rotate the volume by any amount, there is no visible difference. I tried 0, 1, 10, 45, 89, and 90 deg. What am I doing wrong?<br><br>When a volume is rotated, the dimensions of the volume in the output mhd file should account for it, right? So rotating 45 deg should increase one of the dimensions.<br>
<div style="margin-left: 40px;"><br><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include "itkImage.h"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include "itkImageFileReader.h"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include "itkImageFileWriter.h"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include "itkResampleImageFilter.h"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include "itkLinearInterpolateImageFunction.h"</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">#include "itkAffineTransform.h"</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">int main( int argc, char * argv[] )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">{</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> if( argc < 4 )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> std::cerr << "Usage: " << std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> std::cerr << argv[0] << " inputImageFile outputImageFile degrees" << std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> return EXIT_FAILURE;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> const unsigned int Dimension = 3;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> typedef unsigned short InputPixelType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> typedef unsigned short OutputPixelType;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> typedef itk::Image< InputPixelType, Dimension > InputImageType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> typedef itk::Image< OutputPixelType, Dimension > OutputImageType;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> typedef itk::ImageFileReader< InputImageType > ReaderType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> typedef itk::ImageFileWriter< OutputImageType > WriterType;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> ReaderType::Pointer reader = ReaderType::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> WriterType::Pointer writer = WriterType::New();</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> reader->SetFileName( argv[1] );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> writer->SetFileName( argv[2] );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> const double angleInDegrees = atof( argv[3] );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> typedef itk::ResampleImageFilter<</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> InputImageType, OutputImageType > FilterType;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> FilterType::Pointer filter = FilterType::New();</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> typedef itk::AffineTransform< double, Dimension > TransformType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> TransformType::Pointer transform = TransformType::New();</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> typedef itk::LinearInterpolateImageFunction<</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> InputImageType, double > InterpolatorType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> InterpolatorType::Pointer interpolator = InterpolatorType::New();</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> filter->SetInterpolator( interpolator );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> filter->SetDefaultPixelValue( 100 );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> reader->Update();</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> const InputImageType * inputImage = reader->GetOutput();</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> const InputImageType::SpacingType & spacing = inputImage->GetSpacing();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> const InputImageType::PointType & origin = inputImage->GetOrigin();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> InputImageType::SizeType size =</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> inputImage->GetLargestPossibleRegion().GetSize();</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> filter->SetOutputOrigin( origin );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> filter->SetOutputSpacing( spacing );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> filter->SetOutputDirection( inputImage->GetDirection() );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> filter->SetSize( size );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> filter->SetInput( reader->GetOutput() );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> writer->SetInput( filter->GetOutput() );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> TransformType::OutputVectorType translation1;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> const double imageCenterX = origin[0] + spacing[0] * size[0] / 2.0;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> const double imageCenterY = origin[1] + spacing[1] * size[1] / 2.0;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> const double imageCenterZ = origin[2] + spacing[2] * size[2] / 2.0;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> translation1[0] = -imageCenterX;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> translation1[1] = -imageCenterY;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> translation1[2] = -imageCenterZ;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> transform->Translate( translation1 );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> std::cout << "imageCenterX = " << imageCenterX << std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> std::cout << "imageCenterY = " << imageCenterY << std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> std::cout << "imageCenterZ = " << imageCenterZ << std::endl;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> const double degreesToRadians = vcl_atan(1.0) / 45.0;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> const double angle = angleInDegrees * degreesToRadians;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> transform->Rotate3D( -angle, false );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> TransformType::OutputVectorType translation2;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> translation2[0] = imageCenterX;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> translation2[1] = imageCenterY;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> translation2[2] = imageCenterZ;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> transform->Translate( translation2, false );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> filter->SetTransform( transform );</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> try</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> writer->Update();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> catch( itk::ExceptionObject & excep )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> std::cerr << "Exception caught !" << std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> std::cerr << excep << std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> return EXIT_SUCCESS;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;">
</div>
<br>
<br>
<br><br><br><br><div class="gmail_quote">On Tue, Nov 30, 2010 at 9:29 PM, Luis Ibanez <span dir="ltr"><<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Kevin<br>
<div class="im"><br>
On Tue, Nov 30, 2010 at 1:23 PM, Kevin Neff <<a href="mailto:kevin.l.neff@gmail.com">kevin.l.neff@gmail.com</a>> wrote:<br>
><br>
> Thanks, Dan. I used the example ImageRegistration8.cxx with my data.<br>
><br>
> First, it's terribly slow. Is there anything I can do to speed it up?<br>
<br>
<br>
</div>1) How long it took ?<br>
<br>
2) How many cores do you have ?<br>
<br>
3) What version of ITK are you using ?<br>
<br>
4) Make sure that you compile it for Release mode.<br>
(that easily makes a difference of 10x with respect to Debug mode).<br>
<div class="im"><br>
<br>
> my limited experience, applying a threshold first and skipping rotation of<br>
> voxels below the threshold helped. Or could I pre-compute isotropic voxels<br>
> and skip the interpolation that follows image rotation and just interpolate<br>
> the final solution? Any suggestion is welcome!<br>
><br>
<br>
</div>You could also use a Mask,<br>
See example:<br>
<br>
ITK/Examples/Registration/ImageRegistration12.cxx<br>
<div class="im"><br>
<br>
> Second, after 200 iterations, the output does not appear correct. I ran it<br>
> with data that had the dimensions 13888x560x48 and 1388x560x53 but the<br>
> output had the dimensions 13888x560x48. The volumes were of the shell of a<br>
> large object, rotated 90 deg, so I'm sure the dimension of the output should<br>
> have been much larger---something like 1388x1000x100.<br>
<br>
</div>a) 90 degrees is beyond the capture radio of any registration method.<br>
You must initialize the Transform to account for most of that rotation.<br>
In practice you shouldn't expect the optimization process to correct<br>
for more than 20 to 30 degrees of rotation.<br>
<br>
b) Is that rotation along the long axis of your image ? or perpendicular to it ?<br>
A screen shot of your image will be very helpful...<br>
<br>
c) You should carefully control the parameter scales to make sure that<br>
you account for the proportion of radians units (used for rotation) to<br>
millimeters used for translation.<br>
<br>
d) What is the pixel spacing of your images ?<br>
<div><div></div><div class="h5"><br>
<br>
><br>
> KLN<br>
><br>
><br>
><br>
><br>
><br>
> On Sun, Nov 21, 2010 at 7:55 AM, Dan Mueller <<a href="mailto:dan.muel@gmail.com">dan.muel@gmail.com</a>> wrote:<br>
>><br>
>> Hi Kevin,<br>
>><br>
>> I highly recommending the entire ITK Software Guide:<br>
>> <a href="http://www.itk.org/ItkSoftwareGuide.pdf" target="_blank">http://www.itk.org/ItkSoftwareGuide.pdf</a><br>
>><br>
>> For your specific question, see section 8.8.<br>
>><br>
>> In short:<br>
>><br>
>> IdentityTransform: identity<br>
>> TranslationTransform: n-D translation<br>
>> ScaleTransform: n-D scaling<br>
>> CenteredRigid2DTransform: 2-D rotation + translation<br>
>> Similarity2DTransform: 2-D scaling + rotation + translation<br>
>> VersorTransform: 3-D rotation<br>
>> VersorRigid3DTransform: 3-D rotation + translation<br>
>> Similarity3DTransform: 3-D scaling + rotation + translation<br>
>> AffineTransform: n-D scaling + rotation + translation + shear<br>
>><br>
>> HTH<br>
>><br>
>> Cheers, Dan<br>
>><br>
>> On 21 November 2010 13:49, Kevin Neff <<a href="mailto:kevin.l.neff@gmail.com">kevin.l.neff@gmail.com</a>> wrote:<br>
>> ><br>
>> > I need to register images using rotation and translation. Is that<br>
>> > possible<br>
>> > with theITK classes, or do I have to write my own?<br>
>> ><br>
>> > I'm basing this question on a translation-only example and the list of<br>
>> > classes derived from AffineTransform<br>
>> ><br>
>> > <a href="http://www.itk.org/Wiki/ITK_Image_Registration" target="_blank">http://www.itk.org/Wiki/ITK_Image_Registration</a><br>
><br>
><br>
</div></div>> _____________________________________<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>
><br>
><br>
</blockquote></div><br>