EMAN::SqEuclideanCmp Class Reference

Squared Euclidean distance normalized by n between 'this' and 'with'. More...

#include <cmp.h>

Inheritance diagram for EMAN::SqEuclideanCmp:

Inheritance graph
[legend]
Collaboration diagram for EMAN::SqEuclideanCmp:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 SqEuclideanCmp ()
float cmp (EMData *image, EMData *with) const
 To compare 'image' with another image passed in through its parameters.
string get_name () const
 Get the Cmp's name.
string get_desc () const
TypeDict get_param_types () const
 Get Cmp parameter information in a dictionary.

Static Public Member Functions

static CmpNEW ()


Detailed Description

Squared Euclidean distance normalized by n between 'this' and 'with'.

Definition at line 191 of file cmp.h.


Constructor & Destructor Documentation

EMAN::SqEuclideanCmp::SqEuclideanCmp (  )  [inline]

Definition at line 194 of file cmp.h.

Referenced by NEW().

00194 {}


Member Function Documentation

float SqEuclideanCmp::cmp ( EMData image,
EMData with 
) const [virtual]

To compare 'image' with another image passed in through its parameters.

An optional transformation may be used to transform the 2 images.

Parameters:
image The first image to be compared.
with The second image to be comppared.
Returns:
The comparison result. Smaller better by default

Implements EMAN::Cmp.

Definition at line 139 of file cmp.cpp.

References dm, ENTERFUNC, EXITFUNC, EMAN::EMData::get_const_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Dict::has_key(), EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), nx, ny, EMAN::Cmp::params, and EMAN::Cmp::validate_input_args().

00140 {
00141         ENTERFUNC;
00142         validate_input_args(image, with);
00143 
00144         const float *const y_data = with->get_const_data();
00145         const float *const x_data = image->get_const_data();
00146         double result = 0.;
00147         float n = 0.0f;
00148         if(image->is_complex() && with->is_complex()) {
00149         // Implemented by PAP  01/09/06 - please do not change.  If in doubts, write/call me.
00150                 int nx  = with->get_xsize();
00151                 int ny  = with->get_ysize();
00152                 int nz  = with->get_zsize();
00153                 nx = (nx - 2 + with->is_fftodd()); // nx is the real-space size of the input image
00154                 int lsd2 = (nx + 2 - nx%2) ; // Extended x-dimension of the complex image
00155 
00156                 int ixb = 2*((nx+1)%2);
00157                 int iyb = ny%2;
00158                 //
00159                 if(nz == 1) {
00160                 //  it looks like it could work in 3D, but it is not, really.
00161                 for ( int iz = 0; iz <= nz-1; iz++) {
00162                         double part = 0.;
00163                         for ( int iy = 0; iy <= ny-1; iy++) {
00164                                 for ( int ix = 2; ix <= lsd2 - 1 - ixb; ix++) {
00165                                                 size_t ii = ix + (iy  + iz * ny)* lsd2;
00166                                                 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
00167                                 }
00168                         }
00169                         for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) {
00170                                 size_t ii = (iy  + iz * ny)* lsd2;
00171                                 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
00172                                 part += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]);
00173                         }
00174                         if(nx%2 == 0) {
00175                                 for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) {
00176                                         size_t ii = lsd2 - 2 + (iy  + iz * ny)* lsd2;
00177                                         part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
00178                                         part += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]);
00179                                 }
00180 
00181                         }
00182                         part *= 2;
00183                         part += (x_data[0] - y_data[0])*double(x_data[0] - y_data[0]);
00184                         if(ny%2 == 0) {
00185                                 int ii = (ny/2  + iz * ny)* lsd2;
00186                                 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
00187                         }
00188                         if(nx%2 == 0) {
00189                                 int ii = lsd2 - 2 + (0  + iz * ny)* lsd2;
00190                                 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
00191                                 if(ny%2 == 0) {
00192                                         int ii = lsd2 - 2 +(ny/2  + iz * ny)* lsd2;
00193                                         part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
00194                                 }
00195                         }
00196                         result += part;
00197                 }
00198                 n = (float)nx*(float)ny*(float)nz*(float)nx*(float)ny*(float)nz;
00199 
00200                 }else{ //This 3D code is incorrect, but it is the best I can do now 01/09/06 PAP
00201                 int ky, kz;
00202                 int ny2 = ny/2; int nz2 = nz/2;
00203                 for ( int iz = 0; iz <= nz-1; iz++) {
00204                         if(iz>nz2) kz=iz-nz; else kz=iz;
00205                         for ( int iy = 0; iy <= ny-1; iy++) {
00206                                 if(iy>ny2) ky=iy-ny; else ky=iy;
00207                                 for ( int ix = 0; ix <= lsd2-1; ix++) {
00208                                 // Skip Friedel related values
00209                                 if(ix>0 || (kz>=0 && (ky>=0 || kz!=0))) {
00210                                                 size_t ii = ix + (iy  + iz * ny)* lsd2;
00211                                                 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
00212                                         }
00213                                 }
00214                         }
00215                 }
00216                 n = ((float)nx*(float)ny*(float)nz*(float)nx*(float)ny*(float)nz)/2.0f;
00217                 }
00218         } else {
00219                 size_t totsize = image->get_xsize()*image->get_ysize()*image->get_zsize();
00220                 if (params.has_key("mask")) {
00221                   EMData* mask;
00222                   mask = params["mask"];
00223                   const float *const dm = mask->get_const_data();
00224                   for (size_t i = 0; i < totsize; i++) {
00225                            if (dm[i] > 0.5) {
00226                                 double temp = x_data[i]- y_data[i];
00227                                 result += temp*temp;
00228                                 n++;
00229                            }
00230                   }
00231                 } else {
00232                   for (size_t i = 0; i < totsize; i++) {
00233                                 double temp = x_data[i]- y_data[i];
00234                                 result += temp*temp;
00235                    }
00236                    n = (float)totsize;
00237                 }
00238         }
00239         result/=n;
00240 
00241         EXITFUNC;
00242         return static_cast<float>(result);
00243 }

string EMAN::SqEuclideanCmp::get_name (  )  const [inline, virtual]

Get the Cmp's name.

Each Cmp is identified by a unique name.

Returns:
The Cmp's name.

Implements EMAN::Cmp.

Definition at line 198 of file cmp.h.

00199                 {
00200                         return "sqeuclidean";
00201                 }

string EMAN::SqEuclideanCmp::get_desc (  )  const [inline, virtual]

Implements EMAN::Cmp.

Definition at line 203 of file cmp.h.

00204                 {
00205                         return "Squared Euclidean distance (sum(a - b)^2)/n.";
00206                 }

static Cmp* EMAN::SqEuclideanCmp::NEW (  )  [inline, static]

Definition at line 208 of file cmp.h.

References SqEuclideanCmp().

00209                 {
00210                         return new SqEuclideanCmp();
00211                 }

TypeDict EMAN::SqEuclideanCmp::get_param_types (  )  const [inline, virtual]

Get Cmp parameter information in a dictionary.

Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.

Returns:
A dictionary containing the parameter info.

Implements EMAN::Cmp.

Definition at line 213 of file cmp.h.

References EMAN::EMObject::EMDATA, EMAN::EMObject::INT, and EMAN::TypeDict::put().

00214                 {
00215                         TypeDict d;
00216                         d.put("mask", EMObject::EMDATA, "image mask");
00217                         d.put("keepzero", EMObject::INT, "If set, zero pixels will not be adjusted in the linear density optimization");
00218                         return d;
00219                 }


The documentation for this class was generated from the following files:

Generated on Sat Nov 21 02:20:17 2009 for EMAN2 by  doxygen 1.5.6