<div dir="ltr">not sure if it was covered on this thread but i believe the v4 version of mattes would allow you to avoid this problem.   <div><br></div><div style>the implementation is slightly different in that the user determines the point set and then passes it into the metric via  SetPointSet</div>

</div><div class="gmail_extra"><br clear="all"><div><div><br></div>brian<br><div><br></div><div><br></div></div>
<br><br><div class="gmail_quote">On Tue, Mar 12, 2013 at 11:31 AM, Seth Gilchrist <span dir="ltr">&lt;<a href="mailto:seth@mech.ubc.ca" target="_blank">seth@mech.ubc.ca</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr">Hi Lien,<div>Sorry for the confusion, by resampling I was thinking of the sampling that happens between your runs in which you are checking for consistency.  It appears you are doing this with your redefinition of SampleFixedImageRegion(). It seems that it must be a thread issue.</div>

<span class="HOEnZb"><font color="#888888">

<div><br></div><div>Seth</div></font></span><div class="gmail_extra">
<br><br><div class="gmail_quote"><div class="im">On Tue, Mar 12, 2013 at 7:00 AM, lien lee <span dir="ltr">&lt;<a href="mailto:lienlee@gmail.com" target="_blank">lienlee@gmail.com</a>&gt;</span> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">







<div><div class="im">
Hi Seth,
<div><br>
</div>
<div>Thanks for your input. I want to make sure I understand you correctly. I assume that you are suggesting to call vMetric-&gt;SetUseFixedImageIndexes(true); and then manage to create and use an index list of the sample points, so that I can avoid the random
 sampling process.  But, I am not so sure I understand your term &quot;re-sampling&quot;. I looked into itk source code carefully. I found that the sampling process (for creating the list of samples) was called in itk::ImageToImageMetric::MultiThreadingInitialize(),
 which is called in itk::MultiResolutionImageRegistrationMethod::Initialize().  That is to say, the sample list is created only once for one image resolution level, but it must be re-created for a new image resolution level since it is actually a new image
 object.  Therefore, looks to me, there is no redundant repeated sampling process to avoid.</div>
<div><br>
</div>
<div>In the sense of avoiding the random sampling procedure, I created a sub-class of MattesMetric, and rewrote the SampleFixedImageRegion() function, where I gave up the random sampling strategy and just used all the odd indices of the points in my fixed image
 mask. Unfortunately, the results are still inconsistent, which makes me prone to believe that this is the problem of thread safety when two masks are applied as I mentioned after I tried Bradley&#39;s suggestion. </div>



</div><div><div class="h5"><div><div>
<div><br>
</div>
<div><br>
<br>
<div class="gmail_quote">2013/3/11 Seth Gilchrist <span dir="ltr">&lt;<a href="mailto:seth@mech.ubc.ca" target="_blank">seth@mech.ubc.ca</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Hi Lien,
<div>Could you use create a sub class of the MattesMetric and define a new function GetFixedImageIndexes() to give you the indexes? You could then use SetFixedImageIndexes( &lt;your index list&gt; ) and that would prevent re-sampling. Maybe put in a request to have
 GetFixedImgeIndexes() added at some point.</div>
<span><font color="#888888">
<div><br>
</div>
<div>Seth</div>
</font></span>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">
<div>On Mon, Mar 11, 2013 at 10:29 AM, lien lee <span dir="ltr">&lt;<a href="mailto:lienlee@gmail.com" target="_blank">lienlee@gmail.com</a>&gt;</span> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<div>Hi Bradley,
<div><br>
</div>
<div>Sorry for the late response.</div>
<div><br>
</div>
<div>Just now, I tried what you have suggested, and I do see consistent results among different runs on the two computers I have. So, the problem should be that it is not thread safe when applying the two masks. I am wondering what I should do next, since the
 single-threaded program runs slowly. Is there any solution that I can use faster multi-threading technique and still keep the results consistent? Does ITK v4 do a better job in this regards?</div>
<div><br>
</div>
<div>BTW, another trial was done before I set <span style="color:rgb(34,34,34);font-size:14px;font-family:arial,sans-serif">ITK_GLOBAL_DEFAULT_NUMBER_OF_</span><span style="color:rgb(34,34,34);font-size:14px;font-family:arial,sans-serif">THREADS to 1.</span></div>




<div>I called vMetric-&gt;SetNumberOfThreads(1), and I noticed that most of the time only one thread was working through starring at the CPU usage in Windows Task Manager.  But still, the results were inconsistent in different runs. I could not explain this. I
 mention it just because it might mean something to itk-developers.</div>
<div><br>
Thanks!</div>
</div>
<div>
<div>
<div><br>
<br>
<div class="gmail_quote">2013/3/1 Bradley Lowekamp <span dir="ltr">&lt;<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">
<div>
<div>Hello,
<div><br>
</div>
<div>How many threads are you running? Have you tried setting the environment variable ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS to 1, to see of the results then become consistent?</div>
<div><br>
</div>
<div>Brad</div>
</div>
</div>
<div><br>
<div>
<div>
<div>
<div>
<div>
<div>On Feb 28, 2013, at 5:52 PM, lien lee &lt;<a href="mailto:lienlee@gmail.com" target="_blank">lienlee@gmail.com</a>&gt; wrote:</div>
<br>
</div>
</div>
</div>
</div>
<blockquote type="cite">
<div>
<div>
<div>
<div>Hi itk-users,
<div><br>
</div>
<div>I took a further step today.  I derived a class from MattesMutualInformationImageToImageMetric, and made it being the metric, so that, I could sneak into itk and visit the protected member ImageToImageMetric&lt; TFixedImage, TMovingImage &gt;::m_FixedImageSamples.
 I printed out a couple of sample points (their coordinates and image values), and I also printed out the seed value of the random number generator, which I set as ReinitializeSeed(76926294).  I get the seed value by calling Statistics::MersenneTwisterRandomVariateGenerator::GetInstance()-&gt;GetSeed();</div>




<div>In different runs, I do see same seed were used, but I also do see different sample points.  I tried this on two different computers, at both of which I saw the inconsistent results. Seems to be the random number generator is non-deterministic even with
 same seed.  However, the weird thing is if I do not use the image mask, it would be consistent. </div>
<div><br>
</div>
<div>Any thoughts?</div>
</div>
</div>
<div><br>
<br>
<div class="gmail_quote">2013/2/26 lien lee <span dir="ltr">&lt;<a href="mailto:lienlee@gmail.com" target="_blank">lienlee@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<div><span style="color:rgb(34,34,34);font-size:14px;font-family:arial,sans-serif">Hi Seth,</span>
<div style="color:rgb(34,34,34);font-size:14px;font-family:arial,sans-serif"><br>
</div>
<div style="color:rgb(34,34,34);font-size:14px;font-family:arial,sans-serif">By clicking the link you provided, the code I saw there is as partly attached, which is different from what I have with ITK 4.2 on my computer.  </div>




<div>
<div style="color:rgb(34,34,34);font-size:14px;font-family:arial,sans-serif"><br>
</div>
<div style="color:rgb(34,34,34);font-size:14px;font-family:arial,sans-serif">I do not have experience with this code, and I am not exactly sure how it works.  But, looks to me, optimizer would call the function during each iteration, and the function would
 rebuild all the sample points again and again for all the iterations.  If my understanding were correct, this would be quite different from what I have with ITK 4.2 on my computer, where all the samples were created in MattesMutualInformationImageToImageMetric::Initialize()
 as <b>a one time thing</b>, and the counted points would be determined for each iteration using the current transform by checking whether the mapped points were inside the moving image mask. Therefore, for the code I am working on, to my understanding, if
 I called ReinitializeSeed(76926294) before generating all the sample points in MattesMutualInformationImageToImageMetric::Initialize(), the results should be deterministic, no matter whether I applied the image masks or not. But, the testing results with image
 mask applied does NOT support my understanding.</div>
<div style="color:rgb(34,34,34);font-size:14px;font-family:arial,sans-serif"><br>
</div>
<div style="color:rgb(34,34,34);font-size:14px;font-family:arial,sans-serif">BTW, to your question, my moving image mask may not be &quot;restrictive&quot; because it occupied pretty much about 80% of the whole moving image.</div>




<div style="color:rgb(34,34,34);font-size:14px;font-family:arial,sans-serif"><br>
</div>
<div style="color:rgb(34,34,34);font-size:14px;font-family:arial,sans-serif">Thanks again for your inputs.</div>
<div style="color:rgb(34,34,34);font-size:14px;font-family:arial,sans-serif"><br>
</div>
<div style="color:rgb(34,34,34);font-size:14px;font-family:arial,sans-serif"><br>
</div>
</div>
<div>
<div>
<div style="color:rgb(34,34,34);font-size:14px;font-family:arial,sans-serif">
<div style="white-space:pre-wrap;font-family:monospace"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l106" style="font-size:large;color:rgb(153,153,153);text-decoration:initial" target="_blank">106</a><span style="font-size:large">
 template &lt;class TFixedImage, </span><span style="font-size:large">class TMovingImage&gt;</span></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l107" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">107</a>
 void</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l108" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">108</a>
 MutualInformationImageToImageMetric&lt;TFixedImage, TMovingImage&gt;</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l109" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">109</a>
 ::SampleFixedImageDomain(</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l110" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">110</a>
   SpatialSampleContainer &amp; samples) const</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l111" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">111</a>
 {</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l112" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">112</a>
   typedef ImageRandomConstIteratorWithIndex&lt;FixedImageType&gt; RandomIterator;</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l113" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">113</a>
   RandomIterator randIter( this-&gt;m_FixedImage, this-&gt;GetFixedImageRegion() );</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l114" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">114</a>
</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l115" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">115</a>
   randIter.SetNumberOfSamples(m_NumberOfSpatialSamples);</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l116" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">116</a>
   randIter.GoToBegin();</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l117" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">117</a>
</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l118" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">118</a>
   typename SpatialSampleContainer::iterator iter;</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l119" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">119</a>
   typename SpatialSampleContainer::const_iterator end = samples.end();</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l120" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">120</a>
</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l121" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">121</a>
   bool allOutside = true;</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l122" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">122</a>
</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l123" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">123</a>
   this-&gt;m_NumberOfPixelsCounted = 0;    // Number of pixels that map into the</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l124" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">124</a>
                                         // fixed and moving image mask, if</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l125" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">125</a>
                                         // specified</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l126" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">126</a>
                                         // and the resampled fixed grid after</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l127" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">127</a>
                                         // transformation.</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l128" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">128</a>
</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l129" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">129</a>
   // Number of random picks made from the portion of fixed image within the</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l130" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">130</a>
   // fixed mask</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l131" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">131</a>
   SizeValueType numberOfFixedImagePixelsVisited = 0;</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l132" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">132</a>
   SizeValueType dryRunTolerance = this-&gt;GetFixedImageRegion().GetNumberOfPixels();</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l133" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">133</a>
   for( iter = samples.begin(); iter != end; ++iter )</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l134" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">134</a>
     {</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l135" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">135</a>
     // Get sampled index</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l136" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">136</a>
     FixedImageIndexType index = randIter.GetIndex();</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l137" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">137</a>
     // Get sampled fixed image value</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l138" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">138</a>
     ( *iter ).FixedImageValue = randIter.Get();</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l139" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">139</a>
     // Translate index to point</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l140" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">140</a>
     this-&gt;m_FixedImage-&gt;TransformIndexToPhysicalPoint(index,</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l141" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">141</a>
                                                       ( *iter ).FixedImagePointValue);</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l142" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">142</a>
</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l143" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">143</a>
     // If not inside the fixed mask, ignore the point</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l144" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">144</a>
     if( this-&gt;m_FixedImageMask</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l145" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">145</a>
         &amp;&amp; !this-&gt;m_FixedImageMask-&gt;IsInside( ( *iter ).FixedImagePointValue ) )</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l146" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">146</a>
       {</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l147" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">147</a>
       ++randIter; // jump to another random position</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l148" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">148</a>
       continue;</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l149" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">149</a>
       }</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l150" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">150</a>
</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l151" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">151</a>
     if( allOutside )</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l152" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">152</a>
       {</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l153" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">153</a>
       ++numberOfFixedImagePixelsVisited;</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l154" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">154</a>
       if( numberOfFixedImagePixelsVisited &gt; dryRunTolerance )</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l155" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">155</a>
         {</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l156" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">156</a>
         // We randomly visited as many points as is the size of the fixed image</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l157" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">157</a>
         // region.. Too may samples mapped ouside.. go change your transform</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l158" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">158</a>
         itkExceptionMacro(&lt;&lt; &quot;Too many samples mapped outside the moving buffer&quot;);</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l159" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">159</a>
         }</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l160" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">160</a>
       }</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l161" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">161</a>
</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l162" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">162</a>
     MovingImagePointType mappedPoint =</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l163" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">163</a>
       this-&gt;m_Transform-&gt;TransformPoint( ( *iter ).FixedImagePointValue );</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l164" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">164</a>
</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l165" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">165</a>
     // If the transformed point after transformation does not lie within the</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l166" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">166</a>
     // MovingImageMask, skip it.</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l167" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">167</a>
     if( this-&gt;m_MovingImageMask</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l168" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">168</a>
         &amp;&amp; !this-&gt;m_MovingImageMask-&gt;IsInside(mappedPoint) )</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l169" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">169</a>
       {</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l170" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">170</a>
       ++randIter;</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l171" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">171</a>
       continue;</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l172" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">172</a>
       }</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l173" style="color:rgb(153,153,153);text-decoration:initial" target="_blank">173</a>
</font></div>
<div style="white-space:pre-wrap;font-family:monospace"><font size="4"><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD#l174" style="color:rgb(153,153,153);text-decoration:initial" target="_blank"></a></font></div>




</div>
<br>
</div>
</div>
</div>
</div>
<div class="gmail_quote">2013/2/26 Seth Gilchrist <span dir="ltr">&lt;<a href="mailto:seth@mech.ubc.ca" target="_blank">seth@mech.ubc.ca</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Hi Lien,
<div>
<div>
<div>Unfortunately I have not used masks when performing registrations, so can&#39;t help you with this specific problem.</div>
<div><br>
</div>
<div>I took a look at the git blob for the MattesMutual...Metric and was examining how the decision to keep or reject a give point is handled. If you are setting a mask on both the fixed and moving images, this will change what points are used because a check
 is done to see if a point is in the fixed mask and if it is in the moving mask after applying the current transform. Could your moving image mask be too restrictive for the early stages of the registration?</div>
<div><br>
</div>
<div>You can read the code at:</div>
<div><a href="http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD" target="_blank">http://itk.org/gitweb?p=ITK.git;a=blob;f=Modules/Registration/Common/include/itkMutualInformationImageToImageMetric.hxx;h=1244e5c0be768696cf042f6f39739f4b2bdcbba6;hb=HEAD</a><br>




</div>
<div><br>
</div>
<div>Starting on line 108, specifically on line 162.</div>
<div><br>
</div>
<div>Cheers,</div>
<div>Seth</div>
<div class="gmail_extra"><br clear="all">
<div><i>Seth Gilchrist, MASc, PhD Candidate<br>
<span style="font-family:courier new,monospace">+---------------------------------------+</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">Orthopaedic and Injury Biomechanics Group<br>
UBC Department of Mechanical Engineering</span><span style="font-family:courier new,monospace"></span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">6th Floor-2635 Laurel Street</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">Vancouver, BC V5Z-1M9<br>
</span><span style="font-family:courier new,monospace">+---------------------------------------+<br>
<a href="mailto:seth@mech.ubc.ca" target="_blank">seth@mech.ubc.ca</a><br>
Fax <a href="tel:604-675-2576" value="+16046752576" target="_blank">604-675-2576</a></span></i></div>
<br>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</blockquote>
</div>
<br>
</div>
</div>
</div>
<div>_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div></div></div></div></div>

</blockquote></div><br></div></div>
<br>_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<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></div>