<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">you did not set lower and upper bounds to the metric's histogram. The following addition alleviates crashing:</div><div class="gmail_default" style="font-size:small"><div class="gmail_default"><font face="monospace, monospace">metric->SetLowerBound(histogramSize);</font></div><div class="gmail_default"><font face="monospace, monospace">metric->SetUpperBound(histogramSize);</font></div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">Regards,</div><div class="gmail_default" style="font-family:verdana,sans-serif">Dženan</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Oct 7, 2016 at 6:48 PM, 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 tried to modify the <wbr>MutualInformationImageToImageF<wbr>ilter example and tried to make it read images and calculate their normalized mutual informaion. Here is the code:<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>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_354924470782327089gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>const unsigned int ImageDimension = 2;</div><div><span class="m_354924470782327089gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>typedef signed short PixelType;</div><div><span class="m_354924470782327089gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>typedef itk::Image<PixelType, ImageDimension> FixedImage;</div><div><span class="m_354924470782327089gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>typedef itk::Image<PixelType, ImageDimension> MovingImage;</div><div><br></div><div><span class="m_354924470782327089gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>typedef itk::ImageFileReader<<wbr>FixedImage> FixedImageTypeReader;</div><div><span class="m_354924470782327089gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>typedef itk::ImageFileReader<<wbr>MovingImage> MovingImageTypeReader;</div><div><br></div><div><span class="m_354924470782327089gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>FixedImageTypeReader::Pointer fixedreader = FixedImageTypeReader::New();</div><div><span class="m_354924470782327089gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>MovingImageTypeReader::Pointer movingreader = MovingImageTypeReader::New();</div><div><br></div><div><span class="m_354924470782327089gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>fixedreader->SetFileName(argv[<wbr>1]);</div><div><span class="m_354924470782327089gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>movingreader->SetFileName(<wbr>argv[2]);</div><div><br></div><div><span class="m_354924470782327089gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>fixedreader->Update();</div><div><span class="m_354924470782327089gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>movingreader->Update();</div><div><span class="m_354924470782327089gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>FixedImage::Pointer fixedImage = fixedreader->GetOutput();</div><div><span class="m_354924470782327089gmail-Apple-tab-span" style="white-space:pre-wrap"> </span>MovingImage::Pointer movingImage = movingreader->GetOutput();</div><div><br></div><div><span class="m_354924470782327089gmail-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::<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>transform);</div><div><br></div><div><br></div><div> metric->SetFixedImageRegion(<wbr>fixedImage-><wbr>GetLargestPossibleRegion());</div><div> </div><div> MetricType::HistogramType::<wbr>SizeType histogramSize;</div><div> histogramSize.SetSize(2);</div><div> histogramSize[0] = 64;</div><div> histogramSize[1] = 64;</div><div><br></div><div> metric->SetHistogramSize(<wbr>histogramSize);</div><div><br></div><div> const unsigned int numberOfParameters = transform-><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> metric->SetFixedImageRegion(<wbr>fixedImage-><wbr>GetLargestPossibleRegion());</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> TranslationTransformType::<wbr>ParametersType parameters;</div><div> parameters.SetSize(2);</div><div> parameters.Fill(0);</div><div> std::cout << "parameters: " << parameters << std::endl;</div><div> printf("before problem\n");</div><div> MetricType::MeasureType value = metric->GetValue(parameters);</div><div> printf("after problem\n");</div><div> std::cout << "Value: " << value << std::endl;</div><div><br></div><div> return EXIT_SUCCESS;</div><div>}</div></div><div><br></div><div>The problem is that every time I call metric->GetValue(parameters); the programme crashes. What could be the problem???</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>