Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::SqEuclideanCmp Class Reference

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

#include <cmp.h>

Inheritance diagram for EMAN::SqEuclideanCmp:

[legend]
Collaboration diagram for EMAN::SqEuclideanCmp:
[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

CmpNEW ()

Static Public Attributes

const string NAME = "sqeuclidean"

Detailed Description

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

Definition at line 192 of file cmp.h.


Constructor & Destructor Documentation

EMAN::SqEuclideanCmp::SqEuclideanCmp  )  [inline]
 

Definition at line 195 of file cmp.h.

00195 {}


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 151 of file cmp.cpp.

References dm, EMAN::EMData::get_attr(), EMAN::EMData::get_const_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::EMData::has_attr(), EMAN::Dict::has_key(), EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), nx, ny, EMAN::EMData::process(), EMAN::EMData::set_attr(), EMAN::Dict::set_default(), and EMAN::Cmp::validate_input_args().

00152 {
00153         ENTERFUNC;
00154         EMData *with = withorig;
00155         validate_input_args(image, with);
00156 
00157         int zeromask = params.set_default("zeromask",0);
00158         int normto = params.set_default("normto",0);
00159 
00160         if (normto) {
00161                 with = withorig->process("normalize.toimage",Dict("to",image));
00162                 with->set_attr("deleteme",1);
00163                 if ((float)(with->get_attr("norm_mult"))<=0) {          // This means the normalization inverted the image, a clear probablity of noise bias, so we undo the normalization
00164                         delete with;
00165                         with=withorig;
00166                 }
00167         }
00168 
00169         const float *const y_data = with->get_const_data();
00170         const float *const x_data = image->get_const_data();
00171         double result = 0.;
00172         float n = 0.0f;
00173         if(image->is_complex() && with->is_complex()) {
00174         // Implemented by PAP  01/09/06 - please do not change.  If in doubts, write/call me.
00175                 int nx  = with->get_xsize();
00176                 int ny  = with->get_ysize();
00177                 int nz  = with->get_zsize();
00178                 nx = (nx - 2 + with->is_fftodd()); // nx is the real-space size of the input image
00179                 int lsd2 = (nx + 2 - nx%2) ; // Extended x-dimension of the complex image
00180 
00181                 int ixb = 2*((nx+1)%2);
00182                 int iyb = ny%2;
00183                 //
00184                 if(nz == 1) {
00185                 //  it looks like it could work in 3D, but it is not, really.
00186                 for ( int iz = 0; iz <= nz-1; iz++) {
00187                         double part = 0.;
00188                         for ( int iy = 0; iy <= ny-1; iy++) {
00189                                 for ( int ix = 2; ix <= lsd2 - 1 - ixb; ix++) {
00190                                                 size_t ii = ix + (iy  + iz * ny)* lsd2;
00191                                                 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
00192                                 }
00193                         }
00194                         for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) {
00195                                 size_t ii = (iy  + iz * ny)* lsd2;
00196                                 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
00197                                 part += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]);
00198                         }
00199                         if(nx%2 == 0) {
00200                                 for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) {
00201                                         size_t ii = lsd2 - 2 + (iy  + iz * ny)* lsd2;
00202                                         part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
00203                                         part += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]);
00204                                 }
00205 
00206                         }
00207                         part *= 2;
00208                         part += (x_data[0] - y_data[0])*double(x_data[0] - y_data[0]);
00209                         if(ny%2 == 0) {
00210                                 int ii = (ny/2  + iz * ny)* lsd2;
00211                                 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
00212                         }
00213                         if(nx%2 == 0) {
00214                                 int ii = lsd2 - 2 + (0  + iz * ny)* lsd2;
00215                                 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
00216                                 if(ny%2 == 0) {
00217                                         int ii = lsd2 - 2 +(ny/2  + iz * ny)* lsd2;
00218                                         part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
00219                                 }
00220                         }
00221                         result += part;
00222                 }
00223                 n = (float)nx*(float)ny*(float)nz*(float)nx*(float)ny*(float)nz;
00224 
00225                 }else{ //This 3D code is incorrect, but it is the best I can do now 01/09/06 PAP
00226                 int ky, kz;
00227                 int ny2 = ny/2; int nz2 = nz/2;
00228                 for ( int iz = 0; iz <= nz-1; iz++) {
00229                         if(iz>nz2) kz=iz-nz; else kz=iz;
00230                         for ( int iy = 0; iy <= ny-1; iy++) {
00231                                 if(iy>ny2) ky=iy-ny; else ky=iy;
00232                                 for ( int ix = 0; ix <= lsd2-1; ix++) {
00233                                 // Skip Friedel related values
00234                                 if(ix>0 || (kz>=0 && (ky>=0 || kz!=0))) {
00235                                                 size_t ii = ix + (iy  + iz * ny)* lsd2;
00236                                                 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]);
00237                                         }
00238                                 }
00239                         }
00240                 }
00241                 n = ((float)nx*(float)ny*(float)nz*(float)nx*(float)ny*(float)nz)/2.0f;
00242                 }
00243         } else {                // real space
00244                 size_t totsize = image->get_xsize()*image->get_ysize()*image->get_zsize();
00245                 if (params.has_key("mask")) {
00246                   EMData* mask;
00247                   mask = params["mask"];
00248                   const float *const dm = mask->get_const_data();
00249                   for (size_t i = 0; i < totsize; i++) {
00250                            if (dm[i] > 0.5) {
00251                                 double temp = x_data[i]- y_data[i];
00252                                 result += temp*temp;
00253                                 n++;
00254                            }
00255                   }
00256                 } 
00257                 else if (zeromask) {
00258                         n=0;
00259                         for (size_t i = 0; i < totsize; i++) {
00260                                 if (x_data[i]==0 || y_data[i]==0) continue;
00261                                 double temp = x_data[i]- y_data[i];
00262                                 result += temp*temp;
00263                                 n++;
00264                         }
00265                         
00266                 }
00267                 else {
00268                   for (size_t i = 0; i < totsize; i++) {
00269                                 double temp = x_data[i]- y_data[i];
00270                                 result += temp*temp;
00271                    }
00272                    n = (float)totsize;
00273                 }
00274         }
00275         result/=n;
00276 
00277         EXITFUNC;
00278         if (with->has_attr("deleteme")) delete with;
00279         return static_cast<float>(result);
00280 }

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

Implements EMAN::Cmp.

Definition at line 204 of file cmp.h.

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

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 199 of file cmp.h.

00200                 {
00201                         return NAME;
00202                 }

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 214 of file cmp.h.

References EMAN::TypeDict::put().

00215                 {
00216                         TypeDict d;
00217                         d.put("mask", EMObject::EMDATA, "image mask");
00218                         d.put("zeromask", EMObject::INT, "If set, zero pixels in either image will be excluded from the statistics");
00219                         d.put("normto",EMObject::INT,"If set, 'with' is normalized to 'this' before computing the distance");
00220                         return d;
00221                 }

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

Definition at line 209 of file cmp.h.

00210                 {
00211                         return new SqEuclideanCmp();
00212                 }


Member Data Documentation

const string SqEuclideanCmp::NAME = "sqeuclidean" [static]
 

Definition at line 44 of file cmp.cpp.


The documentation for this class was generated from the following files:
Generated on Fri Apr 30 15:39:13 2010 for EMAN2 by  doxygen 1.3.9.1