Aviv,<br><br>I recognize that you spent unnecessary time fighting with an unexpected implementation of a metric, and are looking for someone to fix the issue.&nbsp; One of the great benefits of the ITK software process is that every filter should have a test and the test should show how to use the filter.&nbsp; In the case of the GradientDifferenceImageToImageMetric, the test does not perfectly address your issue in that it does not actually set up and use the metric in the context of an optimizer, however it does evaluate the metric at various translations of the moving and fixed image ... the same type of evaulations that would be generated by an optimizer exploring the space around a solution.&nbsp; The output from the test clearly shows that the metric is at a maximum when the two images are fully aligned (offset [0,0] - see below for the test output.)&nbsp; Again, I realize that this is not optimal from the standpoint of plugging filters together in an <i>ad hoc</i> fashion, but when you run into a problem, it is important to look for and understand the tests of the code.&nbsp; These tests can provide important clues as to how your particular usage differs from the expected usage of the code, as well as giving you insight into parameter settings, etc.&nbsp; For this metric, the source for the test can be found at &quot;Insight\Testing\Code\Algorithm\itkGradientDifferenceImageToImageMetricTest.cxx&quot; and the test can be executed by running &quot;itkAlgorithmsTests2&quot; and selecting option 4 (after building with Testing/Examples On).<br>
<br>I realize that this won&#39;t help your current frustration, but as you continue to use ITK, you will find that this is a good habit to cultivate.&nbsp; Good luck!<br><br>- Wes<br><br>Output form the itkGradientDifferenceImageToImageMetricTest:<br>
<br>To run a test, enter the test number: 4<br>Parameters: [-10, -10], Value: 16315.6, Derivatives: [7875.2, 7875.2]<br>Parameters: [-5, -10], Value: 16818.4, Derivatives: [17033.4, 8163.25]<br>Parameters: [0, -10], Value: 17279, Derivatives: [83531.2, 19402.1]<br>
Parameters: [5, -10], Value: 16869.3, Derivatives: [-114.142, 16730.5]<br>Parameters: [10, -10], Value: 16334.2, Derivatives: [-93.3736, 11243.7]<br>Parameters: [-10, -5], Value: 16818.4, Derivatives: [8163.25, 17033.4]<br>
Parameters: [-5, -5], Value: 17732.6, Derivatives: [18762.5, 18762.5]<br>Parameters: [0, -5], Value: 18478, Derivatives: [-9044.31, 54419.4]<br>Parameters: [5, -5], Value: 17777.6, Derivatives: [-190.489, 40302.4]<br>Parameters: [10, -5], Value: 16905.5, Derivatives: [-148.262, 21012.2]<br>
Parameters: [-10, 0], Value: 17279, Derivatives: [19402.1, 83531.2]<br>Parameters: [-5, 0], Value: 18478, Derivatives: [54419.4, -9044.32]<br>Parameters: [0, 0], Value: 20000, Derivatives: [458406, 458406]<br>Parameters: [5, 0], Value: 18839.7, Derivatives: [-317.508, 271044]<br>
Parameters: [10, 0], Value: 17453.9, Derivatives: [-223.557, 105338]<br>Parameters: [-10, 5], Value: 16869.3, Derivatives: [16730.5, -114.142]<br>Parameters: [-5, 5], Value: 17777.6, Derivatives: [40302.4, -190.489]<br>Parameters: [0, 5], Value: 18839.7, Derivatives: [271044, -317.508]<br>
Parameters: [5, 5], Value: 18024.8, Derivatives: [-225.825, -225.825]<br>Parameters: [10, 5], Value: 17003.7, Derivatives: [-171.369, -127.79]<br>Parameters: [-10, 10], Value: 16334.2, Derivatives: [11243.7, -93.3736]<br>
Parameters: [-5, 10], Value: 16905.5, Derivatives: [21012.2, -148.262]<br>Parameters: [0, 10], Value: 17453.9, Derivatives: [105338, -223.557]<br>Parameters: [5, 10], Value: 17003.7, Derivatives: [-127.79, -171.369]<br>Parameters: [10, 10], Value: 16401.4, Derivatives: [-105.449, -105.449]<br>
GradientDifferenceImageToImageMetric (01685300)<br><br><div class="gmail_quote">On Thu, Jun 26, 2008 at 8:40 AM, Aviv Hurvitz &lt;<a href="mailto:aviv.hurvitz@gmail.com">aviv.hurvitz@gmail.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I saw that in the docs.<br><br>In my opinion that bit, and the cited paper, are not enough for users to understand what needs to be done. The fact is that it confused me, and apparently others as well, and the cost of this confusion was big. <br>

<br>I suggested a few solutions:<br>1. Change the metric to go down.<br>2. Add a flag to all image metrics that says which way they go.<br>3. Clarify the metric direction in the docs.<br><br>You say #1 is impossible since it might break old code, and I agree. (reluctantly... :) <br>

#2 is best, I think, since it would allow both kinds of metrics to be plugged into the same framework.<br>#3 is probably worst, because it would only solve the problem in this particular metric, and it would still leave room for user errors.<br>

<br>Having read the code, I got the feeling that no one has used this metric successfully. Sadly, I can&#39;t actually PROVE it now with a smoking gun. I&#39;m curious to know if there is any reader out there who uses this metric. I&#39;m not saying that we have a license to break it, I&#39;m just giving you some background about how I feel about this metric. In my opinion, it&#39;s not on par with the rest of ITK, with regards to documentation, test cases, and code quality.<br>

<br>I wish this thread wouldn&#39;t end with the conclusion that everything is
perfect just the way it is. Would someone please acknowledge that there
is a problem?<br><br>Regards,<br><font color="#888888"><br>- Aviv</font><div><div></div><div class="Wj3C7c"><br><br><br><div class="gmail_quote">On Thu, Jun 26, 2008 at 1:17 PM, Hauke Heibel &lt;<a href="mailto:heibel@cs.tum.edu" target="_blank">heibel@cs.tum.edu</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Aviv Hurvitz wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
All the metrics I know in ITK go &quot;down&quot;. There was no special documentation, ...<br>
</blockquote>
As a matter of fact there is. Take a look at <a href="http://www.itk.org/Doxygen34/html/classitk_1_1GradientDifferenceImageToImageMetric.html" target="_blank">http://www.itk.org/Doxygen34/html/classitk_1_1GradientDifferenceImageToImageMetric.html</a><br>


It states &quot;after passing the squared difference through a function of type 1/(1+x)&quot;.<br>
<br>
And I would not expect the functionality to change since there are many people who got the usage right and whose code would break if the class&#39;s functionality would change.<br>
<br>
- Hauke<br><font color="#888888">
<br>
-- <br>
Tim Hauke Heibel<br>
Computer Aided Medical Procedures (CAMP)<br>
fon: +49 89 289 19427<br>
fax: +49 89 289 17059<br>
<br>
</font></blockquote></div><br>
</div></div><br>_______________________________________________<br>
Insight-users mailing list<br>
<a href="mailto:Insight-users@itk.org">Insight-users@itk.org</a><br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Wesley D. Turner, Ph.D.<br>Kitware, Inc.<br>R&amp;D Engineer<br>28 Corporate Drive<br>Clifton Park, NY 12065-8662<br>Phone: 518-371-3971 x120