/* // // Copyright 1997-2009 Torsten Rohlfing // // Copyright 2004-2010 SRI International // // This file is part of the Computational Morphometry Toolkit. // // http://www.nitrc.org/projects/cmtk/ // // The Computational Morphometry Toolkit is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public // License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. // // The Computational Morphometry Toolkit is distributed in the hope that it // will be useful, but WITHOUT ANY WARRANTY; without even the implied // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with the Computational Morphometry Toolkit. If not, see // . // // $Revision: 5436 $ // // $LastChangedDate: 2018-12-10 19:01:20 -0800 (Mon, 10 Dec 2018) $ // // $LastChangedBy: torstenrohlfing $ // */ #include "cmtkScalarImageSimilarity.h" #include namespace cmtk { /** \addtogroup Registration */ //@{ ScalarImageSimilarity::ReturnType ScalarImageSimilarity::GetRegionalMutualInformation ( const ScalarImage* image0, const ScalarImage* image1, const int radius ) { // printf("REGIONAL MUTUAL INFORMATION\n"); const ScalarImage::IndexType& dims = image0->GetDims(); int nrows = dims[1]; int ncols = dims[0]; int d = 2*radius+1; int N = (ncols-2*radius)*(nrows-2*radius); int d2 = d*d; int dim = 2*d2; Types::DataItem* pts = Memory::ArrayC::Allocate( N*dim ); Types::DataItem tmp1, tmp2; const TypedArray *data1 = image0->GetPixelData(); const TypedArray *data2 = image1->GetPixelData(); int idx,nidx,lidx; nidx = 0; idx = 0; lidx = 0; // printf("creating neighborhood...\n"); // CREATE NEIGHBORHOOD VECTORS for (int i=radius; iGet(tmp1,idx); data2->Get(tmp2,idx); pts[lidx*N + nidx] = tmp1; pts[(lidx+d2)*N + nidx] = tmp2; lidx++; } } nidx++; } } // printf("done.\n"); // SUBTRACT MEAN // printf("subtracting mean...\n"); std::vector mean(dim,0.0); for (int i=0; i cM( dim, dim ); ScalarImageSimilarity::ReturnType sum; int iN, jN; for (int i=0; i mcM( dim/2, dim/2 ); // image0's bloc for (int i=0; i