Dear all,<div><br></div><div>I have a deformation field of size 128 X 128 X 124 (vector is 3D), and a mask image of size 128 X 128 X 124. I use a ImageRegionIterator on each of them. The purpose is to assigned the masked region in deformation field to its mean value. The following is how I do it:</div>
<div> </div><div>I first set up 2 iterators, one for deformation field, one for mask image. Size the size of these two images are the same. So I use mask image iterator to find the corresponding deformation field pixel. Then I calculate the mean value of the masked deformation field region. At the end I start over again to assign the mean value to the masked region and get a new deformation field. </div>
<div><br></div><div>By doing so, if I apply the new deformation field on the mask used before, I expect the mask image will not be nonrigidly deformed, since for only translation should happen on the masked area. However, this does not happen. Is there anything wrong here? </div>
<div><br></div><div>The core code is at the end of the email, I also put on the code an testing image at :<a href="http://www.mediafire.com/file/wyzvkdnhnmo/MeanDeformationFieldCode.zip">http://www.mediafire.com/file/wyzvkdnhnmo/MeanDeformationFieldCode.zip</a></div>
<div><br></div><div><br></div><div><div> /** Setup iterator over outputtmp. */</div><div> itk::ImageRegionIterator< DeformationFieldType > oit(</div><div> outputtmp, outputtmp->GetLargestPossibleRegion() );</div>
<div><br></div><div><br></div><div> /** Set iterator over mask image */</div><div> itk::ImageRegionIterator< MaskImageType > mit(</div><div> maskImage, maskImage->GetLargestPossibleRegion() );</div><div>
<br></div><div> oit.GoToBegin();</div><div> mit.GoToBegin();</div><div><br></div><div><br></div><div><br></div><div><br></div><div> /** The actual work. */</div><div> while ( !oit.IsAtEnd() ) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> /** add the vector value within the mask **/</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> if ( mit.Get() > 0.000001 ) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span> sum += oit.Get();</div><div><span class="Apple-tab-span" style="white-space:pre">                </span> sumc++;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> }</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> ++oit;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> ++mit;</div>
<div> }</div><div> </div><div> /** Get the mean value*/</div><div> VectorType mean = sum / sumc;</div><div><br></div><div><br></div><div><br></div><div> </div><div> oit.GoToBegin();</div><div> mit.GoToBegin();</div>
<div><br></div><div> /* Copy value */</div><div> while ( !oit.IsAtEnd() )</div><div> {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> if ( mit.Get() > 0.000001 ) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span> oit.Set( mean );</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> } </div><div><span class="Apple-tab-span" style="white-space:pre">        </span> ++mit;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> ++oit;</div>
<div> }</div></div>