<div dir="ltr">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.<br><br><div>#include "itkImage.h"</div><div>#include "itkCenteredRigid2DTransform.h"</div><div>#include "itkImageFileReader.h"</div><div>#include "itkNormalizeImageFilter.h"</div><div>#include "itkResampleImageFilter.h"</div><div>#include "itkImageFileWriter.h"</div><div>#include "itkImageFileReader.h"</div><div>#include "itkCastImageFilter.h"</div><div>#include"itkLinearInterpolateImageFunction.h"</div><div>#include "itkExceptionObject.h"</div><div>typedef itk::Image<unsigned char, 2>  ImageType;</div><div><br></div><div><br></div><div><br></div><div>int main(int argc, char *argv[])</div><div>{</div><div><span class="" style="white-space:pre"> </span>typedef itk::Image<unsigned char, 2> OutputImageType;</div><div><span class="" style="white-space:pre">        </span>typedef itk::ImageFileReader<ImageType> ReaderType;</div><div><span class="" style="white-space:pre">  </span>typedef itk::CenteredRigid2DTransform<double> TransformType;</div><div><span class="" style="white-space:pre"> </span>typedef itk::ImageFileWriter<OutputImageType> WriterType;</div><div><br></div><div><span class="" style="white-space:pre">   </span>ReaderType::Pointer reader = ReaderType::New();</div><div><span class="" style="white-space:pre">    </span>TransformType::Pointer transform = TransformType::New();</div><div><span class="" style="white-space:pre">   </span>WriterType::Pointer writer = WriterType::New();</div><div><br></div><div><span class="" style="white-space:pre">   </span></div><div><br></div><div><span class="" style="white-space:pre">  </span>reader->SetFileName(argv[1]);</div><div><span class="" style="white-space:pre">   </span>reader->Update();</div><div><br></div><div><span class="" style="white-space:pre">      </span>writer->SetFileName(argv[2]);</div><div><span class="" style="white-space:pre">   </span></div><div><span class="" style="white-space:pre">   </span>TransformType::TranslationType t;</div><div><span class="" style="white-space:pre">  </span>TransformType::CenterType c;</div><div><span class="" style="white-space:pre">       </span>ImageType::SizeType s;</div><div><span class="" style="white-space:pre">     </span></div><div><span class="" style="white-space:pre">   </span>transform->SetRotation(atof(argv[3]));</div><div><br></div><div><br></div><div><span class="" style="white-space:pre">        </span>t[0] = atof(argv[4]);</div><div><span class="" style="white-space:pre">      </span>t[1] = atof(argv[5]);</div><div><span class="" style="white-space:pre">      </span>transform->SetTranslation(t);</div><div><br></div><div><span class="" style="white-space:pre">  </span></div><div><br></div><div><span class="" style="white-space:pre">  </span>s = reader->GetOutput()->GetLargestPossibleRegion().GetSize();</div><div><span class="" style="white-space:pre">       </span>c[0] = (s[0]-1)/2.0;</div><div><span class="" style="white-space:pre">       </span>c[1] = (s[1]-1)/2.0;</div><div><span class="" style="white-space:pre">       </span>transform->SetCenter(c);</div><div><span class="" style="white-space:pre">        </span>std::cout << "size: " << reader->GetOutput()->GetLargestPossibleRegion().GetSize() << std::endl;</div><div><span class="" style="white-space:pre"> </span>std::cout << "center: " << c << std::endl;</div><div><br></div><div><span class="" style="white-space:pre">    </span>typedef itk::ResampleImageFilter<ImageType, OutputImageType> ResampleImageFilterType;</div><div><span class="" style="white-space:pre">        </span>ResampleImageFilterType::Pointer resamplefilter = ResampleImageFilterType::New();</div><div><span class="" style="white-space:pre">  </span></div><div><span class="" style="white-space:pre">   </span>resamplefilter->SetTransform(transform.GetPointer());</div><div><span class="" style="white-space:pre">   </span>resamplefilter->SetInput(reader->GetOutput());</div><div><span class="" style="white-space:pre">       </span></div><div><span class="" style="white-space:pre">   </span>ImageType::Pointer image = reader->GetOutput();</div><div><span class="" style="white-space:pre"> </span></div><div><span class="" style="white-space:pre">   </span>typedef itk::LinearInterpolateImageFunction<ImageType, double> InterpolationType;</div><div><br></div><div><span class="" style="white-space:pre">   </span>InterpolationType::Pointer interp = InterpolationType::New();</div><div><br></div><div><span class="" style="white-space:pre">     </span>interp->SetInputImage(image);</div><div><br></div><div><span class="" style="white-space:pre">  </span></div><div><br></div><div><span class="" style="white-space:pre">  </span>ImageType::SizeType size = image->GetLargestPossibleRegion().GetSize();</div><div><span class="" style="white-space:pre"> </span>resamplefilter->SetSize(size);</div><div><span class="" style="white-space:pre">  </span>resamplefilter->SetOutputOrigin(image->GetOrigin());</div><div><span class="" style="white-space:pre"> </span>resamplefilter->SetOutputSpacing(image->GetSpacing());</div><div><span class="" style="white-space:pre">       </span>resamplefilter->SetOutputDirection(image->GetDirection());</div><div><span class="" style="white-space:pre">   </span>std::cout << image->GetSpacing();</div><div><span class="" style="white-space:pre"> </span>resamplefilter->SetDefaultPixelValue(0);</div><div><span class="" style="white-space:pre">        </span>resamplefilter->SetInterpolator(interp);</div><div><br></div><div><span class="" style="white-space:pre">       </span>resamplefilter->Update();</div><div><span class="" style="white-space:pre">       </span></div><div><span class="" style="white-space:pre">   </span></div><div><span class="" style="white-space:pre">   </span></div><div><span class="" style="white-space:pre">   </span></div><div><span class="" style="white-space:pre">   </span>writer->SetInput(resamplefilter->GetOutput());</div><div><span class="" style="white-space:pre">       </span>try{</div><div><span class="" style="white-space:pre">               </span>writer->Update();</div><div><span class="" style="white-space:pre">       </span>}</div><div><span class="" style="white-space:pre">  </span>catch (itk::ExceptionObject &err){</div><div><span class="" style="white-space:pre">             </span>std::cout << "ExceptionObject caught !" << std::endl;</div><div><span class="" style="white-space:pre">                </span>std::cout << err << std::endl;</div><div><span class="" style="white-space:pre">         </span>return EXIT_FAILURE;</div><div><br></div><div><span class="" style="white-space:pre">      </span>}</div><div><span class="" style="white-space:pre">  </span></div><div><br></div><div><span class="" style="white-space:pre">  </span></div><div>  return EXIT_SUCCESS;</div><div>}</div><div><br></div><div><br></div></div><div id="DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><table style="border-top:1px solid #aaabb6;margin-top:30px">
        <tr>
                <td style="width:105px;padding-top:15px">
                        <a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" target="_blank"><img src="https://ipmcdn.avast.com/images/logo-avast-v1.png" style="width: 90px; height:33px;"></a>
                </td>
                <td style="width:470px;padding-top:20px;color:#41424e;font-size:13px;font-family:Arial,Helvetica,sans-serif;line-height:18px">Το παρόν email στάλθηκε από ασφαλή υπολογιστή που προστατεύεται από το Avast. <br><a href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" target="_blank" style="color:#4453ea">www.avast.com</a>                </td>
        </tr>
</table>
<a href="#DDB4FAA8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"></a></div>