<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2800.1276" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Verdana color=#0000ff size=2><SPAN
class=231215913-13082004>Monica, </SPAN></FONT></DIV>
<DIV><FONT face=Verdana color=#0000ff size=2><SPAN
class=231215913-13082004></SPAN></FONT> </DIV>
<DIV><FONT face=Verdana color=#0000ff size=2><SPAN class=231215913-13082004>I
forgot something in my last message. The calls to
interpolator->Evaluate() should be within an if block that checks that the
point is within the image, for instance</SPAN></FONT></DIV>
<DIV><FONT face=Verdana color=#0000ff size=2><SPAN
class=231215913-13082004></SPAN></FONT> </DIV>
<DIV><FONT><SPAN class=231215913-13082004>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2> // interpolate a vector from the smaller image at
this physical position </FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana><FONT color=#0000ff><FONT
size=2> <SPAN class=231215913-13082004>if
(interpolator->IsInsideBuffer(p)</SPAN></FONT></FONT></FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana><FONT color=#0000ff><FONT
size=2><SPAN class=231215913-13082004>
{</SPAN></FONT></FONT></FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana><FONT color=#0000ff><FONT
size=2><SPAN class=231215913-13082004>
</SPAN>v2 = interpolator->Evaluate(p);</FONT></FONT></FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><SPAN class=231215913-13082004><FONT
face=Verdana color=#0000ff
size=2> }</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><SPAN class=231215913-13082004><FONT
face=Verdana color=#0000ff
size=2> else</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><SPAN class=231215913-13082004><FONT
face=Verdana color=#0000ff size=2>
{</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><SPAN class=231215913-13082004><FONT
face=Verdana color=#0000ff size=2> v2.Fill(
0.0 );</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><SPAN class=231215913-13082004><FONT
face=Verdana color=#0000ff size=2>
}</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><SPAN class=231215913-13082004><FONT
face=Verdana color=#0000ff size=2></FONT></SPAN></SPAN> </DIV>
<DIV><SPAN class=596342912-13082004><SPAN
class=231215913-13082004></SPAN></SPAN> </DIV></SPAN></FONT></DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B> Miller, James V (Research)
[mailto:millerjv@crd.ge.com]<BR><B>Sent:</B> Friday, August 13, 2004 9:57
AM<BR><B>To:</B> 'Monica Lumbardi'; 'Luis Ibanez'<BR><B>Cc:</B>
'insight-users@itk.org'<BR><B>Subject:</B> RE: [Insight-users] Addition of two
DeformationFields<BR><BR></FONT></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2>Monica, </FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2>The issue with the AddImageFilter is that it relies on the
NumericTraits class to define a</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2>type for accumulating the results. For instance, if you are
adding to char images, you would use an accumulate type of short to avoid
overflow during the accumulation.</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2>There is not specialization for
NumericTraits<Vector<T>>. You might try putting one in your
code (you can use one of the existing specializations to see what traits need
to be defined). But I don't think this will work given the class heirarchy for
NumericTraits.</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff size=2>We
could add another algorithm to specifically add two vector
images.</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2>However, looking back at your original question, it sounds like your
two deformation fields are at different resolutions. So the smaller one would
need to be interpolated. You could something like</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2>typedef itk::VectorLinearInterpolateImageFunction<SmallImageType>
VectorInterpolatorType;</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2>VectorInterpolatorType::Pointer interpolator =
VectorInterpolatorType::New();</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2>interpolator->SetInputImage( smallField );</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2>OutputIteratorType outIt = OutputIteratorType(cumulativeField,
region);</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2>LargeInputIteratorType inIt = LargeInputIteratorType(largeField,
region);</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2>VectorType v1, v2;</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2>PointType p;</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2>while (!inIt.IsAtEnd())</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2>{</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff size=2>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2> largeField->TransfromIndexToPhysicalPoint(
inIt.GetIndex(), p );</FONT></SPAN></DIV> v1 =
inIt.Get();</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2> // interpolate a vector from the smaller image
at this physical position </FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2> v2 =
interpolator->Evaluate(p);</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2> // set the output vector as the sum of the two
vectors</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004> <FONT face=Verdana
color=#0000ff size=2>outIt.Set( v1 + v2 );</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=596342912-13082004> <FONT face=Verdana
color=#0000ff size=2> ++inIt;</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2> ++outIt;</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2>}</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff size=2>I
trust that adding deformation is what you really want to do. In
particular, you are </FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2>looking to add two vectors at the same physical position. This is
what the above code does. If you are looking to "concatenate" or "compose" to
vector fields, where you apply one vector field to a set of positions, then
apply another vector field, then you use inner loop code that looks
like </FONT></SPAN></DIV><SPAN class=596342912-13082004></SPAN><FONT
face=Tahoma><FONT face=Verdana color=#0000ff size=2></FONT><FONT face=Verdana
color=#0000ff size=2></FONT>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2>{</FONT></SPAN></DIV><SPAN class=596342912-13082004>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2> largeField->TransfromIndexToPhysicalPoint(
inIt.GetIndex(), p );</FONT></SPAN></DIV>
<DIV><FONT face=Verdana color=#0000ff size=2> v1 =
inIt.Get();</FONT></DIV>
<DIV><FONT face=Verdana color=#0000ff size=2></FONT> </DIV>
<DIV><FONT face=Verdana color=#0000ff size=2><SPAN
class=596342912-13082004> // to compose the vector fields,
apply the first vector field to the position</SPAN></FONT></DIV>
<DIV></SPAN><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2> newp = p + v1;</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2> </FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2> // interpolate the vector to compose with from the
smaller image</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2> v2 =
interpolator->Evaluate(newp);</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2> // apply the second vector field to
position</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004> <FONT face=Verdana
color=#0000ff size=2>newp += v2;</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2> // composite vector is the difference between the
original point and the moved point</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004> <FONT face=Verdana
color=#0000ff size=2>outIt.Set( newp - p );</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=596342912-13082004> <FONT face=Verdana
color=#0000ff size=2> ++inIt;</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2> ++outIt;</FONT></SPAN></DIV>
<DIV><SPAN class=596342912-13082004><FONT face=Verdana color=#0000ff
size=2>}</FONT></SPAN></DIV>
<DIV> </DIV>
<DIV><FONT face=Verdana color=#0000ff size=2><SPAN class=596342912-13082004>If
you want, you can put in a feature request on the ITK bug tracker for a filter
that will composite two vector fields.</SPAN></FONT></DIV>
<DIV><FONT face=Verdana color=#0000ff size=2></FONT> </DIV>
<DIV><BR><FONT size=2><SPAN class=596342912-13082004><FONT face=Verdana
color=#0000ff>[Jim Miller] </FONT></SPAN></FONT></DIV>
<DIV><FONT size=2><SPAN
class=596342912-13082004></SPAN></FONT> </DIV></BLOCKQUOTE></FONT></BODY></HTML>