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