[ITK] Trouble in centered 2d rigid transformation

Constantinus Spanakis c.spanakis83 at gmail.com
Thu Jan 21 14:37:18 EST 2016


Hello. I face a problem in transforming a 2D image. I give the program
specific rotation angle and translation and i get different results from
matlab. To be specific, i have dicom image p006_pd.dcm and i want to
transform it to test.tif. The transformation parameters are angle(-0.354528
rads) and translation vector T=[-23.2159   -8.8362]. But when I give the
same parameters for my ITK programme, i get the third image, which is a bit
different from test. What could be the problem? Here's my code.

#include "itkImage.h"
#include "itkCenteredRigid2DTransform.h"
#include "itkImageFileReader.h"
#include "itkNormalizeImageFilter.h"
#include "itkResampleImageFilter.h"
#include "itkImageFileWriter.h"
#include "itkImageFileReader.h"
#include "itkCastImageFilter.h"
#include"itkLinearInterpolateImageFunction.h"
#include "itkExceptionObject.h"
typedef itk::Image<unsigned char, 2>  ImageType;



int main(int argc, char *argv[])
{
typedef itk::Image<unsigned char, 2> OutputImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;
typedef itk::CenteredRigid2DTransform<double> TransformType;
typedef itk::ImageFileWriter<OutputImageType> WriterType;

ReaderType::Pointer reader = ReaderType::New();
TransformType::Pointer transform = TransformType::New();
WriterType::Pointer writer = WriterType::New();


reader->SetFileName(argv[1]);
reader->Update();

writer->SetFileName(argv[2]);
TransformType::TranslationType t;
TransformType::CenterType c;
ImageType::SizeType s;
transform->SetRotation(atof(argv[3]));


t[0] = atof(argv[4]);
t[1] = atof(argv[5]);
transform->SetTranslation(t);


s = reader->GetOutput()->GetLargestPossibleRegion().GetSize();
c[0] = (s[0]-1)/2.0;
c[1] = (s[1]-1)/2.0;
transform->SetCenter(c);
std::cout << "size: " <<
reader->GetOutput()->GetLargestPossibleRegion().GetSize() << std::endl;
std::cout << "center: " << c << std::endl;

typedef itk::ResampleImageFilter<ImageType, OutputImageType>
ResampleImageFilterType;
ResampleImageFilterType::Pointer resamplefilter =
ResampleImageFilterType::New();
resamplefilter->SetTransform(transform.GetPointer());
resamplefilter->SetInput(reader->GetOutput());
ImageType::Pointer image = reader->GetOutput();
typedef itk::LinearInterpolateImageFunction<ImageType, double>
InterpolationType;

InterpolationType::Pointer interp = InterpolationType::New();

interp->SetInputImage(image);


ImageType::SizeType size = image->GetLargestPossibleRegion().GetSize();
resamplefilter->SetSize(size);
resamplefilter->SetOutputOrigin(image->GetOrigin());
resamplefilter->SetOutputSpacing(image->GetSpacing());
resamplefilter->SetOutputDirection(image->GetDirection());
std::cout << image->GetSpacing();
resamplefilter->SetDefaultPixelValue(0);
resamplefilter->SetInterpolator(interp);

resamplefilter->Update();
writer->SetInput(resamplefilter->GetOutput());
try{
writer->Update();
}
catch (itk::ExceptionObject &err){
std::cout << "ExceptionObject caught !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;

}

  return EXIT_SUCCESS;
}


<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Το
παρόν email στάλθηκε από ασφαλή υπολογιστή που προστατεύεται από το Avast.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20160121/84284925/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.tif
Type: image/tiff
Size: 54122 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/community/attachments/20160121/84284925/attachment-0002.tif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p006_t2_pd_novel.tif
Type: image/tiff
Size: 65761 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/community/attachments/20160121/84284925/attachment-0003.tif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p006_pd.dcm
Type: application/octet-stream
Size: 66444 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/community/attachments/20160121/84284925/attachment-0001.obj>


More information about the Community mailing list