#include <cmp.h>
Inheritance diagram for EMAN::SqEuclideanCmp:
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 Cmp * | NEW () |
Static Public Attributes | |
static const string | NAME = "sqeuclidean" |
Definition at line 229 of file cmp.h.
EMAN::SqEuclideanCmp::SqEuclideanCmp | ( | ) | [inline] |
To compare 'image' with another image passed in through its parameters.
An optional transformation may be used to transform the 2 images.
image | The first image to be compared. | |
with | The second image to be comppared. |
Implements EMAN::Cmp.
Definition at line 271 of file cmp.cpp.
References dm, ENTERFUNC, EXITFUNC, EMAN::EMData::get_attr(), EMAN::EMData::get_const_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Util::goodf(), EMAN::EMData::has_attr(), EMAN::Dict::has_key(), EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), nx, ny, EMAN::Cmp::params, EMAN::EMData::process(), EMAN::EMData::set_attr(), EMAN::Dict::set_default(), and EMAN::Cmp::validate_input_args().
00272 { 00273 ENTERFUNC; 00274 EMData *with = withorig; 00275 validate_input_args(image, with); 00276 00277 int zeromask = params.set_default("zeromask",0); 00278 int normto = params.set_default("normto",0); 00279 00280 if (normto) { 00281 if (zeromask) with = withorig->process("normalize.toimage",Dict("to",image)); 00282 else with = withorig->process("normalize.toimage",Dict("to",image,"ignore_zero",0)); 00283 with->set_attr("deleteme",1); 00284 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 00285 delete with; 00286 with=withorig; 00287 } 00288 } 00289 00290 const float *const y_data = with->get_const_data(); 00291 const float *const x_data = image->get_const_data(); 00292 double result = 0.; 00293 float n = 0.0f; 00294 if(image->is_complex() && with->is_complex()) { 00295 // Implemented by PAP 01/09/06 - please do not change. If in doubts, write/call me. 00296 int nx = with->get_xsize(); 00297 int ny = with->get_ysize(); 00298 int nz = with->get_zsize(); 00299 nx = (nx - 2 + with->is_fftodd()); // nx is the real-space size of the input image 00300 int lsd2 = (nx + 2 - nx%2) ; // Extended x-dimension of the complex image 00301 00302 int ixb = 2*((nx+1)%2); 00303 int iyb = ny%2; 00304 // 00305 if(nz == 1) { 00306 // it looks like it could work in 3D, but it is not, really. 00307 for ( int iz = 0; iz <= nz-1; iz++) { 00308 double part = 0.; 00309 for ( int iy = 0; iy <= ny-1; iy++) { 00310 for ( int ix = 2; ix <= lsd2 - 1 - ixb; ix++) { 00311 size_t ii = ix + (iy + iz * ny)* lsd2; 00312 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 00313 } 00314 } 00315 for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) { 00316 size_t ii = (iy + iz * ny)* lsd2; 00317 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 00318 part += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]); 00319 } 00320 if(nx%2 == 0) { 00321 for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) { 00322 size_t ii = lsd2 - 2 + (iy + iz * ny)* lsd2; 00323 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 00324 part += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]); 00325 } 00326 00327 } 00328 part *= 2; 00329 part += (x_data[0] - y_data[0])*double(x_data[0] - y_data[0]); 00330 if(ny%2 == 0) { 00331 int ii = (ny/2 + iz * ny)* lsd2; 00332 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 00333 } 00334 if(nx%2 == 0) { 00335 int ii = lsd2 - 2 + (0 + iz * ny)* lsd2; 00336 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 00337 if(ny%2 == 0) { 00338 int ii = lsd2 - 2 +(ny/2 + iz * ny)* lsd2; 00339 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 00340 } 00341 } 00342 result += part; 00343 } 00344 n = (float)nx*(float)ny*(float)nz*(float)nx*(float)ny*(float)nz; 00345 00346 }else{ //This 3D code is incorrect, but it is the best I can do now 01/09/06 PAP 00347 int ky, kz; 00348 int ny2 = ny/2; int nz2 = nz/2; 00349 for ( int iz = 0; iz <= nz-1; iz++) { 00350 if(iz>nz2) kz=iz-nz; else kz=iz; 00351 for ( int iy = 0; iy <= ny-1; iy++) { 00352 if(iy>ny2) ky=iy-ny; else ky=iy; 00353 for ( int ix = 0; ix <= lsd2-1; ix++) { 00354 // Skip Friedel related values 00355 if(ix>0 || (kz>=0 && (ky>=0 || kz!=0))) { 00356 size_t ii = ix + (iy + iz * ny)* (size_t)lsd2; 00357 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 00358 } 00359 } 00360 } 00361 } 00362 n = ((float)nx*(float)ny*(float)nz*(float)nx*(float)ny*(float)nz)/2.0f; 00363 } 00364 } else { // real space 00365 size_t totsize = (size_t)image->get_xsize()*image->get_ysize()*image->get_zsize(); 00366 if (params.has_key("mask")) { 00367 EMData* mask; 00368 mask = params["mask"]; 00369 const float *const dm = mask->get_const_data(); 00370 for (size_t i = 0; i < totsize; i++) { 00371 if (dm[i] > 0.5) { 00372 double temp = x_data[i]- y_data[i]; 00373 result += temp*temp; 00374 n++; 00375 } 00376 } 00377 } 00378 else if (zeromask) { 00379 n=0; 00380 for (size_t i = 0; i < totsize; i++) { 00381 if (x_data[i]==0 || y_data[i]==0) continue; 00382 double temp = x_data[i]- y_data[i]; 00383 result += temp*temp; 00384 n++; 00385 } 00386 00387 } 00388 else { 00389 for (size_t i = 0; i < totsize; i++) { 00390 double temp = x_data[i]- y_data[i]; 00391 result += temp*temp; 00392 } 00393 n = (float)totsize; 00394 } 00395 } 00396 result/=n; 00397 00398 EXITFUNC; 00399 if (with->has_attr("deleteme")) delete with; 00400 float ret = (float)result; 00401 if (!Util::goodf(&ret)) return FLT_MAX; 00402 return ret; 00403 }
string EMAN::SqEuclideanCmp::get_desc | ( | ) | const [inline, virtual] |
string EMAN::SqEuclideanCmp::get_name | ( | ) | const [inline, virtual] |
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.
Implements EMAN::Cmp.
Definition at line 251 of file cmp.h.
References EMAN::EMObject::EMDATA, EMAN::EMObject::INT, and EMAN::TypeDict::put().
00252 { 00253 TypeDict d; 00254 d.put("mask", EMObject::EMDATA, "image mask"); 00255 d.put("zeromask", EMObject::INT, "If set, zero pixels in either image will be excluded from the statistics"); 00256 d.put("normto",EMObject::INT,"If set, 'with' is normalized to 'this' before computing the distance"); 00257 return d; 00258 }
static Cmp* EMAN::SqEuclideanCmp::NEW | ( | ) | [inline, static] |
Definition at line 246 of file cmp.h.
References SqEuclideanCmp().
00247 { 00248 return new SqEuclideanCmp(); 00249 }
const string SqEuclideanCmp::NAME = "sqeuclidean" [static] |