cmtkRegistration2d2d.cxx

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 2004-2010 SRI International
00004 //
00005 //  Copyright 1997-2009 Torsten Rohlfing
00006 //
00007 //  This file is part of the Computational Morphometry Toolkit.
00008 //
00009 //  http://www.nitrc.org/projects/cmtk/
00010 //
00011 //  The Computational Morphometry Toolkit is free software: you can
00012 //  redistribute it and/or modify it under the terms of the GNU General Public
00013 //  License as published by the Free Software Foundation, either version 3 of
00014 //  the License, or (at your option) any later version.
00015 //
00016 //  The Computational Morphometry Toolkit is distributed in the hope that it
00017 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00018 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License along
00022 //  with the Computational Morphometry Toolkit.  If not, see
00023 //  <http://www.gnu.org/licenses/>.
00024 //
00025 //  $Revision: 2398 $
00026 //
00027 //  $LastChangedDate: 2010-10-05 14:54:37 -0700 (Tue, 05 Oct 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #include "cmtkRegistration2d2d.h"
00034 
00035 #include <Base/cmtkVector.h>
00036 
00037 #include <Registration/cmtkFunctionalAffine2D.h>
00038 #include <Registration/cmtkOptimizer.h>
00039 #include <Registration/cmtkBestNeighbourOptimizer.h>
00040 #include <Registration/cmtkTypedArraySimilarity.h>
00041 #include <Registration/cmtkProtocolCallback.h>
00042 
00043 #include <IO/cmtkPGM.h>
00044 
00045 namespace
00046 cmtk
00047 {
00048 
00051 
00052 void 
00053 Registration2d2d::Register
00054 ( CoordinateMatrix3x3& matrix, ScalarImage::SmartPtr& refImage,
00055   ScalarImage::SmartPtr& fltImage, const ScalarImage::RegionType* fltROI )
00056 {
00057   ScalarImage::SmartPtr roi( new ScalarImage( *(fltImage) ) );
00058 
00059   if ( fltROI ) 
00060     {
00061     roi->SetROI( *fltROI );
00062     Types::Coordinate v[8];
00063     matrix.Decompose( v );
00064     v[0] += fltROI->From()[AXIS_X] * roi->GetPixelSize( AXIS_X );
00065     v[1] += fltROI->From()[AXIS_Y] * roi->GetPixelSize( AXIS_Y );
00066     matrix.Compose( v );
00067     }
00068 
00069   Register( matrix, refImage, roi );
00070 }
00071 
00072 void 
00073 Registration2d2d::Register
00074 ( CoordinateMatrix3x3& matrix, ScalarImage::SmartPtr& refImage,
00075   ScalarImage::SmartPtr& fltImage )
00076 {
00077   SmartPointer<FunctionalAffine2D> functional
00078     ( new FunctionalAffine2D( refImage, fltImage ) );
00079   functional->SetSimilarityMeasure( ScalarImageSimilarity::MI );
00080     
00081   CoordinateMatrix3x3 init( matrix );
00082   
00083   BestNeighbourOptimizer optimizer;
00084   //  RegistrationCallback_P callback
00085   //    ( new ProtocolCallback( "track.txt", true ) );
00086   //  optimizer.SetCallback( callback );
00087     
00088   optimizer.SetFunctional( Functional::SmartPtr::DynamicCastFrom( functional ) );
00089   CoordinateVector v( 8 );
00090   matrix.Decompose( v.Elements );
00091 
00092   const float explore1 = 5.0;
00093   const float accuracy1 = 0.5;
00094   functional->SetNumberDOFs( 3 );
00095   optimizer.Optimize( v, explore1, accuracy1 );
00096 
00097   //  const float explore2 = 2.0;
00098   //  const float accuracy2 = 0.125;
00099   //  functional->SetNumberDOFs( 3 );
00100   //  optimizer.Optimize( v, explore1, accuracy2 );
00101 
00102   matrix.Compose( v.Elements );
00103 
00104   ScalarImage::SmartPtr finalImage( refImage->InterpolateFrom( fltImage, &matrix ) );
00105 
00106   static int cnt = 0;
00107   char fname[12];
00108   snprintf( fname, sizeof( fname ), "fin%03d.pgm", cnt++ );
00109   PGM::Write16bit( fname, finalImage );
00110 }
00111 
00112 } // namespace cmtk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines