<DIV>Hello Robert,</DIV>
<DIV>&nbsp;</DIV>
<DIV>The LBFGS<STRONG>B</STRONG>Optimizer in ITK is constrained. You can set there limits for all variables or only one, like the one representing the rotation. You do not need to&nbsp; write any additional code or make modifications to ITK, &nbsp;just use this optimizer, it is the bounded version of LBFGS. You can find some sample code on how to use this in the testing code.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Edi</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR><BR><B><I>Robert Maroon &lt;robertmaroon@yahoo.com&gt;</I></B> wrote:</DIV>
<BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">
<DIV><FONT face="times new roman" size=3>Thanks for the advice James,</FONT></DIV>
<DIV><FONT face="times new roman" size=3></FONT>&nbsp;</DIV>
<DIV><FONT face="times new roman" size=3>I've been trying to implement it using the subclassing method but even though my code compiles fine it keeps calling the original code&nbsp;from MeanSquaresImageToImageMetric</FONT><FONT face=Verdana> instead of the class I derived from it. I included my header file and a couple of clips from my code to see if anyone can see what I am doing wrong. I am trying to use all the functions of the parent and just replacing GetValueAndDerivative and GetValue with my own subclass. </FONT></DIV>
<DIV><FONT face=Verdana></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana>Thanks in advance! I would really appreciate some help!</FONT></DIV>
<DIV><FONT face=Verdana></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana>In my main project code I call on my class as follows:</FONT></DIV>
<DIV><FONT face=Verdana></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana>I include:</FONT></DIV>
<DIV>#include "myReg.h"</DIV>
<DIV><FONT face=Verdana></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana>And then to declare the metric I do:</FONT></DIV>
<DIV>typedef itk::myReg&lt;FixedImageType,MovingImageType&gt;&nbsp;&nbsp;&nbsp;&nbsp; MetricType;</DIV>
<DIV>&nbsp;</DIV>
<DIV>The rest of the file is basically ImageRegistration5.cxx</DIV>
<DIV><FONT face=Verdana></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana></FONT>&nbsp;</DIV>
<DIV>#ifndef __myReg_h<BR>#define __myReg_h</DIV>
<DIV>#include "itkImageToImageMetric.h"<BR>#include "itkCovariantVector.h"<BR>#include "itkMeanSquaresImageToImageMetric.h"<BR>#include "itkPoint.h"</DIV>
<DIV><BR>namespace itk<BR>{<BR><BR>template &lt; class TFixedImage, class TMovingImage &gt; <BR>class ITK_EXPORT myReg : <BR>&nbsp;&nbsp;&nbsp; public MeanSquaresImageToImageMetric&lt; TFixedImage, TMovingImage&gt;<BR>{</DIV>
<DIV>&nbsp; /**&nbsp; Get the value for single valued optimizers. */<BR>&nbsp; MeasureType GetValue( const TransformParametersType &amp; parameters ) const;</DIV>
<DIV>&nbsp; /**&nbsp; Get value and derivatives for multiple valued optimizers. */<BR>&nbsp; void GetValueAndDerivative( const TransformParametersType &amp; parameters,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MeasureType&amp; Value, DerivativeType&amp; Derivative ) const;</DIV>
<DIV>protected:<BR>&nbsp; myReg();<BR>&nbsp; virtual ~myReg() {};</DIV>
<DIV>};</DIV>
<DIV>} // end namespace itk</DIV>
<DIV><BR>#endif</DIV>
<DIV><FONT face=Verdana></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana>Here's the TXX file:<BR><BR>#ifndef _myReg_txx<BR>#define _myReg_txx</FONT></DIV>
<DIV><FONT face=Verdana>#include "myReg.h"<BR>#include "itkImageRegionConstIteratorWithIndex.h"</FONT></DIV>
<DIV><FONT face=Verdana>namespace itk<BR>{</FONT></DIV>
<DIV><FONT face=Verdana>/*<BR>&nbsp;* Constructor<BR>&nbsp;*/<BR>template &lt;class TFixedImage, class TMovingImage&gt; <BR>myReg&lt;TFixedImage,TMovingImage&gt;<BR>::myReg()<BR>{<BR>&nbsp; std::cout&lt;&lt;"TEST 1!"&lt;&lt;std::endl;<BR>&nbsp; itkDebugMacro("Constructor");<BR>}</FONT></DIV>
<DIV><FONT face=Verdana>/*<BR>&nbsp;* Get the match Measure<BR>&nbsp;*/<BR>template &lt;class TFixedImage, class TMovingImage&gt; <BR>typename myReg&lt;TFixedImage,TMovingImage&gt;::MeasureType<BR>myReg&lt;TFixedImage,TMovingImage&gt;<BR>::GetValue( const TransformParametersType &amp; parameters ) const<BR>{</FONT></DIV>
<DIV><FONT face=Verdana>&nbsp; itkDebugMacro("GetValue( " &lt;&lt; parameters &lt;&lt; " ) ");</FONT></DIV>
<DIV><FONT face=Verdana>&nbsp; FixedImageConstPointer fixedImage = this-&gt;GetFixedImage();</FONT></DIV>
<DIV><FONT face=Verdana>&nbsp; if( !fixedImage ) <BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; itkExceptionMacro( &lt;&lt; "Fixed image has not been assigned" );<BR>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT face=Verdana>&nbsp; typedef&nbsp; itk::ImageRegionConstIteratorWithIndex&lt;FixedImageType&gt; FixedIteratorType;</FONT></DIV><FONT face=Verdana>
<DIV><BR>&nbsp; FixedIteratorType ti( fixedImage, this-&gt;GetFixedImageRegion() );</DIV>
<DIV>&nbsp; typename FixedImageType::IndexType index;</DIV>
<DIV>&nbsp; MeasureType measure = NumericTraits&lt; MeasureType &gt;::Zero;</DIV>
<DIV>&nbsp; m_NumberOfPixelsCounted = 0;</DIV>
<DIV>&nbsp; this-&gt;SetTransformParameters( parameters );</DIV>
<DIV>&nbsp; while(!ti.IsAtEnd())<BR>&nbsp;&nbsp;&nbsp; {</DIV>
<DIV>&nbsp;&nbsp;&nbsp; index = ti.GetIndex();<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; typename Superclass::InputPointType inputPoint;<BR>&nbsp;&nbsp;&nbsp; fixedImage-&gt;TransformIndexToPhysicalPoint( index, inputPoint );</DIV>
<DIV>&nbsp;&nbsp;&nbsp; if( m_FixedImageMask &amp;&amp; !m_FixedImageMask-&gt;IsInside( inputPoint ) )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ++ti;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; continue;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp;&nbsp;&nbsp; typename Superclass::OutputPointType transformedPoint = m_Transform-&gt;TransformPoint( inputPoint );</DIV>
<DIV>&nbsp;&nbsp;&nbsp; if( m_MovingImageMask &amp;&amp; !m_MovingImageMask-&gt;IsInside( transformedPoint ) )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ++ti;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; continue;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp;&nbsp;&nbsp; if( m_Interpolator-&gt;IsInsideBuffer( transformedPoint ) )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const RealType movingValue&nbsp; = m_Interpolator-&gt;Evaluate( transformedPoint );<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const RealType fixedValue&nbsp;&nbsp; = ti.Get();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_NumberOfPixelsCounted++;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const RealType diff = movingValue - fixedValue; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; measure += diff * diff; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp;&nbsp;&nbsp; ++ti;<BR>&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp; if( !m_NumberOfPixelsCounted )<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; itkExceptionMacro(&lt;&lt;"All the points mapped to outside of the moving image");<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; else<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; measure /= m_NumberOfPixelsCounted;<BR>&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp; std::cout&lt;&lt;"TEST2!"&lt;&lt;std::endl;</DIV>
<DIV>&nbsp; if( parameters[0] &gt; 0.087)<BR>&nbsp;&nbsp; measure = measure*(parameters[0]*1000);</DIV>
<DIV>&nbsp; return measure;</DIV>
<DIV>}</DIV>
<DIV>&nbsp;</DIV>
<DIV>/*<BR>&nbsp;* Get both the match Measure and theDerivative Measure <BR>&nbsp;*/<BR>template &lt;class TFixedImage, class TMovingImage&gt; <BR>void<BR>myReg&lt;TFixedImage,TMovingImage&gt;<BR>::GetValueAndDerivative(const TransformParametersType &amp; parameters, <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MeasureType &amp; value, DerivativeType&nbsp; &amp; derivative) const<BR>{</DIV>
<DIV>&nbsp; itkDebugMacro("GetValueAndDerivative( " &lt;&lt; parameters &lt;&lt; " ) ");</DIV>
<DIV>&nbsp; if( !m_GradientImage )<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; itkExceptionMacro(&lt;&lt;"The gradient image is null, maybe you forgot to call Initialize()");<BR>&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp; FixedImageConstPointer fixedImage = this-&gt;GetFixedImage();</DIV>
<DIV>&nbsp; if( !fixedImage ) <BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; itkExceptionMacro( &lt;&lt; "Fixed image has not been assigned" );<BR>&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp; const unsigned int ImageDimension = FixedImageType::ImageDimension;</DIV>
<DIV>&nbsp; typedef&nbsp; itk::ImageRegionConstIteratorWithIndex&lt;<BR>&nbsp;&nbsp;&nbsp; FixedImageType&gt; FixedIteratorType;</DIV>
<DIV>&nbsp; typedef&nbsp; itk::ImageRegionConstIteratorWithIndex&lt;<BR>&nbsp;&nbsp;&nbsp; ITK_TYPENAME Superclass::GradientImageType&gt; GradientIteratorType;</DIV>
<DIV><BR>&nbsp; FixedIteratorType ti( fixedImage, this-&gt;GetFixedImageRegion() );</DIV>
<DIV>&nbsp; typename FixedImageType::IndexType index;</DIV>
<DIV>&nbsp; MeasureType measure = NumericTraits&lt; MeasureType &gt;::Zero;</DIV>
<DIV>&nbsp; m_NumberOfPixelsCounted = 0;</DIV>
<DIV>&nbsp; this-&gt;SetTransformParameters( parameters );</DIV>
<DIV>&nbsp; const unsigned int ParametersDimension = this-&gt;GetNumberOfParameters();<BR>&nbsp; derivative = DerivativeType( ParametersDimension );<BR>&nbsp; derivative.Fill( NumericTraits&lt;ITK_TYPENAME DerivativeType::ValueType&gt;::Zero );</DIV>
<DIV>&nbsp; ti.GoToBegin();</DIV>
<DIV>&nbsp; while(!ti.IsAtEnd())<BR>&nbsp;&nbsp;&nbsp; {</DIV>
<DIV>&nbsp;&nbsp;&nbsp; index = ti.GetIndex();<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; typename Superclass::InputPointType inputPoint;<BR>&nbsp;&nbsp;&nbsp; fixedImage-&gt;TransformIndexToPhysicalPoint( index, inputPoint );</DIV>
<DIV>&nbsp;&nbsp;&nbsp; if( m_FixedImageMask &amp;&amp; !m_FixedImageMask-&gt;IsInside( inputPoint ) )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ++ti;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; continue;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp;&nbsp;&nbsp; typename Superclass::OutputPointType transformedPoint = m_Transform-&gt;TransformPoint( inputPoint );</DIV>
<DIV>&nbsp;&nbsp;&nbsp; if( m_MovingImageMask &amp;&amp; !m_MovingImageMask-&gt;IsInside( transformedPoint ) )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ++ti;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; continue;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp;&nbsp;&nbsp; if( m_Interpolator-&gt;IsInsideBuffer( transformedPoint ) )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const RealType movingValue&nbsp; = m_Interpolator-&gt;Evaluate( transformedPoint );</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const TransformJacobianType &amp; jacobian =<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_Transform-&gt;GetJacobian( inputPoint ); </DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const RealType fixedValue&nbsp;&nbsp;&nbsp;&nbsp; = ti.Value();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_NumberOfPixelsCounted++;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const RealType diff = movingValue - fixedValue; <BR>&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; measure += diff * diff;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Get the gradient by NearestNeighboorInterpolation: <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // which is equivalent to round up the point components.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; typedef typename Superclass::OutputPointType OutputPointType;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; typedef typename OutputPointType::CoordRepType CoordRepType;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; typedef ContinuousIndex&lt;CoordRepType,MovingImageType::ImageDimension&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MovingImageContinuousIndexType;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MovingImageContinuousIndexType tempIndex;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_MovingImage-&gt;TransformPhysicalPointToContinuousIndex( transformedPoint, tempIndex );</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; typename MovingImageType::IndexType mappedIndex; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for( unsigned int j = 0; j &lt; MovingImageType::ImageDimension; j++ )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mappedIndex[j] = static_cast&lt;long&gt;( vnl_math_rnd( tempIndex[j] ) );<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const GradientPixelType gradient = <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_GradientImage-&gt;GetPixel( mappedIndex );</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(unsigned int par=0; par&lt;ParametersDimension; par++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RealType sum = NumericTraits&lt; RealType &gt;::Zero;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(unsigned int dim=0; dim&lt;ImageDimension; dim++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sum += 2.0 * diff * jacobian( dim, par ) * gradient[dim];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; derivative[par] += sum;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp;&nbsp;&nbsp; ++ti;<BR>&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp; if( !m_NumberOfPixelsCounted )<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; itkExceptionMacro(&lt;&lt;"All the points mapped to outside of the moving image");<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; else<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; for(unsigned int i=0; i&lt;ParametersDimension; i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; derivative[i] /= m_NumberOfPixelsCounted;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; measure /= m_NumberOfPixelsCounted;<BR>&nbsp;&nbsp;&nbsp; }</DIV>
<DIV>&nbsp; std::cout&lt;&lt;"TEST 2!"&lt;&lt;std::endl;</DIV>
<DIV>&nbsp; if( parameters[0] &gt; 0.087)<BR>&nbsp;&nbsp; measure = measure*(parameters[0]*1000);</DIV>
<DIV>&nbsp; value = measure;</DIV>
<DIV>}</DIV>
<DIV>} // end namespace itk</DIV>
<DIV><BR>#endif<BR></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV></FONT>
<DIV><FONT face=Verdana></FONT>&nbsp;</DIV>
<DIV><FONT face=Verdana></FONT>&nbsp;</DIV>
<P><FONT face=Verdana></FONT>&nbsp;</P>
<P><FONT face=Verdana></FONT>&nbsp;</P>
<P><FONT face=Verdana></FONT>&nbsp;</P>
<DIV><BR><BR><B><I>"Miller, James V (Research)" &lt;millerjv@crd.ge.com&gt;</I></B> wrote:</DIV>
<BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid">
<META content="MSHTML 6.00.2800.1276" name=GENERATOR>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2>We discussed this a while back.&nbsp; You are essentially asking for a constrained optimization</FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=677103113-04102004>&nbsp;&nbsp;&nbsp; <FONT face=Verdana color=#0000ff size=2>min&nbsp;F(Image1, Image2, Transform)</FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004></SPAN><SPAN class=677103113-04102004>&nbsp;&nbsp;&nbsp; <FONT face=Verdana color=#0000ff size=2>s.t. G(Transform) = 0</FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2>All the image registration in ITK are unconstrained.</FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2>I think there are two ways to do what you want but you will have to write some code.</FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2>The first way is to modify or create new optimizers. Most the ITK optimizers are wrappers around vnl optimizers which are wrappers around netlib/lapack type routines.&nbsp; We'd need </FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2>to wrap a contrained optimization optimizer and develop an API for specifying constraints.&nbsp; This is probably the best solution architectually.</FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2>The second option is to create a new image metric that incorporates your contraint.&nbsp; Here, the metric would incorporate a penalty or additional "cost" for violating the constraints. The metric would evaluate something like:</FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=677103113-04102004>&nbsp;&nbsp;&nbsp; <FONT face=Verdana color=#0000ff size=2>metric =&nbsp;F(Image1, FImage2, Transfrom) + lambda * G(Transform)</FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2>where&nbsp;G(Transform) would be zero for angles below a specified threshold and then increase (linearly?) as the angle exceeds the specified threshold.</FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2>The second way requires less code but is architectually fragile. </FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2></FONT></SPAN><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2>For example, let's take the MeanSquaresImageToImageMetric.&nbsp; The method GetValue()</FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2>takes a set of transformation parameters (vector of parameters) and computes the mean square difference between the images where one of the images is transformed using the specified transformation parameters. Unfortunately, the metric knows nothing about the </FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2>type of transformation being used. The metric simply takes the vector of transformation </FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2>parameters, and via virtual function call to&nbsp;a transform assigned at runtime, it passes the transformation parameter vector to the transform. (This all works in the registration framework because the registration method will call GetParameters() on the transform and pass them to the optimizer/metric.&nbsp; So the parameter vector is implictly consistent between the transform, metric, and optimizer.)</FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2>You could subclass the MeanSquaresImageToImageMetric and add in a penalty term based on the parameter vector passed into routines like GetValue(), GetValueAndDerivative(), etc. But here you would have to peek into specific positions in the parameter vector to check the value of the rotation.&nbsp; This requires knowlege of the type of transform being used.&nbsp;This is why this solution is fragile.</FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2>You could make this less fragile by only allowing your new metric to use a certain type of transform.&nbsp; You could override the SetTransform() method in ImageToImageMetric and check that the specified transform is the type of transform needed.&nbsp; Here, you would dynamic cast the pointer to the specified transform to a the specific type of transform your metric uses (for instance Rigid3DTransform, etc.).&nbsp; If the dynamic_cast returns 0, then the wrong type of transform was specified and you would issue an exception.</FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2>You could make this less fragile by "deducing" the rotation encapsulated in the transform by transforming the vertices of a simplex (in the GetValue() routines) and groking the rotation applied.</FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2>Jim</FONT></SPAN></DIV>
<DIV><SPAN class=677103113-04102004><FONT face=Verdana color=#0000ff size=2></FONT></SPAN>&nbsp;</DIV>
<BLOCKQUOTE>
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma size=2>-----Original Message-----<BR><B>From:</B> Robert Maroon [mailto:robertmaroon@yahoo.com]<BR><B>Sent:</B> Friday, October 01, 2004 4:32 PM<BR><B>To:</B> insight-users@itk.org<BR><B>Subject:</B> [Insight-users] How to limit rotations when registering in ITK?<BR><BR></FONT></DIV>
<DIV>Hi all,</DIV>
<DIV>&nbsp;</DIV>
<DIV>I am trying to use the&nbsp;ImageRegistration5 example found in the ITK examples to register a pair of images but I need to restrict the amount of rotation allowed. I have looked though the examples and documentation and I can't seem to find a way to constrain the angles (say less than&nbsp;x degrees)&nbsp;in which the registration can look. I has looking particular to see if there is anything besides the scaling and MaximumStepLengths that can be set for the optimizer that might let me acheive this.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks!<BR></DIV>
<DIV>Robert</DIV>
<P>
<HR SIZE=1>
Do you Yahoo!?<BR><A href="http://us.rd.yahoo.com/mail_us/taglines/security/*http://promotions.yahoo.com/new_mail/static/protection.html">Yahoo! Mail</A> - You care about security. So do we.</BLOCKQUOTE></BLOCKQUOTE>
<P>
<HR SIZE=1>
Do you Yahoo!?<BR><A href="http://vote.yahoo.com/">vote.yahoo.com</A> - Register online to vote today!_______________________________________________<BR>Insight-users mailing list<BR>Insight-users@itk.org<BR>http://www.itk.org/mailman/listinfo/insight-users<BR></BLOCKQUOTE>