<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Hi Constantinus,</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">the line</div><div class="gmail_default"><font face="monospace, monospace">RigidTransformType::OutputVectorType translation = rigidtransform->GetTranslation();</font><br></div><div class="gmail_default"><font face="verdana, sans-serif">copies the translation into a new variable. Changing the new variable </font><span style="font-family:monospace,monospace">translation</span><font face="verdana, sans-serif"> leaves the </font><font face="monospace, monospace">rigidtransform</font><font face="verdana, sans-serif"> totally unaffected. After setting values to </font><font face="monospace, monospace">translation</font><font face="verdana, sans-serif">, you should do something like </font><font face="monospace, monospace">rigidtransform->SetTranslation(translation);</font></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif">Regards,</font></div><div class="gmail_default"><font face="verdana, sans-serif">Dženan</font></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 22, 2016 at 2:52 AM, Constantinus Spanakis <span dir="ltr"><<a href="mailto:c.spanakis83@gmail.com" target="_blank">c.spanakis83@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello. I want to caculate mutual information between 2 images. The problem is that the outcome changes only when the angle of rotation changes. What could be the problem?<div><br></div><div><div>#include "<wbr>itkMutualInformationImageToIma<wbr>geMetric.h"</div><div>#include "itkRandomImageSource.h"</div><div>#include "itkTranslationTransform.h"</div><div>#include"<wbr>itkCenteredRigid2DTransform.h"</div><div>#include "<wbr>itkCenteredTransformInitialize<wbr>r.h"</div><div>#include "<wbr>itkLinearInterpolateImageFunct<wbr>ion.h"</div><div>#include"itkImageFileReader.h"</div><div>#include"<wbr>itkNormalizedMutualInformation<wbr>HistogramImageToImageMetric.h"</div><div><br></div><div><br></div><div>typedef itk::Image< unsigned char, 2>  ImageType;</div><div>//typedef itk::Image< float, 2> ImageType;</div><div><br></div><div>int main( int argc, char *argv[] )</div><div>{</div><div><br></div><div><span class="m_4124092602646988614gmail-Apple-tab-span" style="white-space:pre-wrap">    </span>const    unsigned int    ImageDimension = 2;</div><div><span class="m_4124092602646988614gmail-Apple-tab-span" style="white-space:pre-wrap">     </span>typedef  unsigned char    PixelType;</div><div><span class="m_4124092602646988614gmail-Apple-tab-span" style="white-space:pre-wrap">      </span>typedef itk::Image<PixelType, ImageDimension> FixedImage;</div><div><span class="m_4124092602646988614gmail-Apple-tab-span" style="white-space:pre-wrap">      </span>typedef itk::Image<PixelType, ImageDimension> MovingImage;</div><div><br></div><div><span class="m_4124092602646988614gmail-Apple-tab-span" style="white-space:pre-wrap">    </span>typedef itk::ImageFileReader<<wbr>FixedImage> FixedImageTypeReader;</div><div><span class="m_4124092602646988614gmail-Apple-tab-span" style="white-space:pre-wrap">      </span>typedef itk::ImageFileReader<<wbr>MovingImage> MovingImageTypeReader;</div><div><br></div><div><span class="m_4124092602646988614gmail-Apple-tab-span" style="white-space:pre-wrap">   </span>FixedImageTypeReader::Pointer fixedreader = FixedImageTypeReader::New();</div><div><span class="m_4124092602646988614gmail-Apple-tab-span" style="white-space:pre-wrap">     </span>MovingImageTypeReader::Pointer movingreader = MovingImageTypeReader::New();</div><div><br></div><div><span class="m_4124092602646988614gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>fixedreader->SetFileName(argv[<wbr>1]);</div><div><span class="m_4124092602646988614gmail-Apple-tab-span" style="white-space:pre-wrap">     </span>movingreader->SetFileName(<wbr>argv[2]);</div><div><br></div><div><span class="m_4124092602646988614gmail-Apple-tab-span" style="white-space:pre-wrap">   </span>fixedreader->Update();</div><div><span class="m_4124092602646988614gmail-Apple-tab-span" style="white-space:pre-wrap">    </span>movingreader->Update();</div><div><span class="m_4124092602646988614gmail-Apple-tab-span" style="white-space:pre-wrap">   </span>FixedImage::Pointer fixedImage = fixedreader->GetOutput();</div><div><span class="m_4124092602646988614gmail-Apple-tab-span" style="white-space:pre-wrap">        </span>MovingImage::Pointer movingImage = movingreader->GetOutput();</div><div><br></div><div><span class="m_4124092602646988614gmail-Apple-tab-span" style="white-space:pre-wrap">    </span></div><div><br></div><div>  typedef itk::TranslationTransform<<wbr>double, 2> TranslationTransformType; // This cannot be float for some reason?</div><div>  TranslationTransformType::<wbr>Pointer transform = TranslationTransformType::New(<wbr>);</div><div><br></div><div>  typedef itk::CenteredRigid2DTransform<<wbr>double> RigidTransformType;</div><div>  typedef itk::<wbr>CenteredTransformInitializer < RigidTransformType, FixedImage, MovingImage> RigidTransformInitializerType;</div><div><br></div><div><br></div><div>  RigidTransformType::Pointer rigidtransform = RigidTransformType::New();</div><div>  RigidTransformInitializerType:<wbr>:Pointer initializer = RigidTransformInitializerType:<wbr>:New();</div><div><br></div><div>  initializer->SetTransform(<wbr>rigidtransform);</div><div>  initializer->SetFixedImage(<wbr>fixedreader->GetOutput());</div><div>  initializer->SetMovingImage(<wbr>movingreader->GetOutput());</div><div>  initializer->GeometryOn();</div><div>  initializer-><wbr>InitializeTransform();</div><div><br></div><div>  rigidtransform-><wbr>SetAngleInDegrees(atof(argv[3]<wbr>));</div><div><br></div><div>  RigidTransformType::<wbr>OutputVectorType translation = rigidtransform-><wbr>GetTranslation();</div><div>  translation[0] = atof(argv[4]);</div><div>  translation[1] = atof(argv[5]);</div><div><br></div><div>  </div><div>  </div><div>  /*typedef itk::<wbr>MutualInformationImageToImageM<wbr>etric<FixedImage, MovingImage >    MetricType;*/</div><div><br></div><div>  typedef itk::<wbr>NormalizedMutualInformationHis<wbr>togramImageToImageMetric<<wbr>FixedImage, MovingImage> MetricType;</div><div><br></div><div><br></div><div>  MetricType::Pointer metric = MetricType::New();</div><div><br></div><div>  metric->SetTransform(<wbr>rigidtransform);</div><div><br></div><div><br></div><div>  metric->SetFixedImageRegion(<wbr>fixedImage-><wbr>GetLargestPossibleRegion());</div><div>  MetricType::<wbr>MeasurementVectorType lower, upper;</div><div>  lower.SetSize(2);</div><div>  lower.Fill(0);</div><div><br></div><div>  upper.SetSize(2);</div><div>  upper.Fill(255);</div><div><br></div><div>  metric->SetLowerBound(lower);</div><div>  metric->SetUpperBound(upper);</div><div>  </div><div>  MetricType::HistogramType::<wbr>SizeType histogramSize;</div><div>  histogramSize.SetSize(2);</div><div>  histogramSize[0] = 128;</div><div>  histogramSize[1] = 128;</div><div><br></div><div>  metric->SetHistogramSize(<wbr>histogramSize);</div><div><br></div><div>  const unsigned int numberOfParameters = rigidtransform-><wbr>GetNumberOfParameters();</div><div>  typedef MetricType::ScalesType ScalesType;</div><div>  ScalesType scales(numberOfParameters);</div><div><br></div><div>  scales.Fill(1.0);</div><div><br></div><div>  metric-><wbr>SetDerivativeStepLengthScales(<wbr>scales);</div><div><br></div><div>  metric->SetFixedImage(<wbr>fixedImage);</div><div>  metric->SetMovingImage(<wbr>movingImage);</div><div><br></div><div><br></div><div>  </div><div><br></div><div>  metric->SetFixedImageRegion(<wbr>fixedImage-><wbr>GetLargestPossibleRegion());</div><div> </div><div><br></div><div>  itk::<wbr>LinearInterpolateImageFunction<wbr><MovingImage, double>::Pointer interpolator = itk::<wbr>LinearInterpolateImageFunction<wbr><MovingImage, double>::New();</div><div>  interpolator->SetInputImage(<wbr>fixedImage);</div><div>  metric->SetInterpolator(<wbr>interpolator);</div><div><br></div><div>  </div><div><br></div><div>  std::cout << fixedreader->GetOutput()-><wbr>GetLargestPossibleRegion().<wbr>GetSize();</div><div>  RigidTransformType::<wbr>InputPointType m = rigidtransform->GetCenter();</div><div>  m[0] = 300;</div><div>  m[1] = 300;</div><div>  rigidtransform->SetCenter(m);</div><div>  std::cout << "parameters: " << rigidtransform->GetParameters(<wbr>) << std::endl;</div><div>  std::cout << "pcenter: " << m << std::endl;</div><div>  </div><div>  metric-><wbr>SetTransformParameters(<wbr>rigidtransform->GetParameters(<wbr>));</div><div>  MetricType::MeasureType value = metric->GetValue(<wbr>rigidtransform->GetParameters(<wbr>));</div><div> </div><div>  std::cout << "Value: " << value << std::endl;</div><div><br></div><div>  return EXIT_SUCCESS;</div><div>}</div></div><div><br></div></div>
<br>______________________________<wbr>_________________<br>
Community mailing list<br>
<a href="mailto:Community@itk.org">Community@itk.org</a><br>
<a href="http://public.kitware.com/mailman/listinfo/community" rel="noreferrer" target="_blank">http://public.kitware.com/<wbr>mailman/listinfo/community</a><br>
<br></blockquote></div><br></div>