#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 228 of file cmp.h.
|
Definition at line 231 of file cmp.h. 00231 {}
|
|
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 244 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(). 00245 { 00246 ENTERFUNC; 00247 EMData *with = withorig; 00248 validate_input_args(image, with); 00249 00250 int zeromask = params.set_default("zeromask",0); 00251 int normto = params.set_default("normto",0); 00252 00253 if (normto) { 00254 if (zeromask) with = withorig->process("normalize.toimage",Dict("to",image)); 00255 else with = withorig->process("normalize.toimage",Dict("to",image,"ignore_zero",0)); 00256 with->set_attr("deleteme",1); 00257 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 00258 delete with; 00259 with=withorig; 00260 } 00261 } 00262 00263 const float *const y_data = with->get_const_data(); 00264 const float *const x_data = image->get_const_data(); 00265 double result = 0.; 00266 float n = 0.0f; 00267 if(image->is_complex() && with->is_complex()) { 00268 // Implemented by PAP 01/09/06 - please do not change. If in doubts, write/call me. 00269 int nx = with->get_xsize(); 00270 int ny = with->get_ysize(); 00271 int nz = with->get_zsize(); 00272 nx = (nx - 2 + with->is_fftodd()); // nx is the real-space size of the input image 00273 int lsd2 = (nx + 2 - nx%2) ; // Extended x-dimension of the complex image 00274 00275 int ixb = 2*((nx+1)%2); 00276 int iyb = ny%2; 00277 // 00278 if(nz == 1) { 00279 // it looks like it could work in 3D, but it is not, really. 00280 for ( int iz = 0; iz <= nz-1; iz++) { 00281 double part = 0.; 00282 for ( int iy = 0; iy <= ny-1; iy++) { 00283 for ( int ix = 2; ix <= lsd2 - 1 - ixb; ix++) { 00284 size_t ii = ix + (iy + iz * ny)* lsd2; 00285 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 00286 } 00287 } 00288 for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) { 00289 size_t ii = (iy + iz * ny)* lsd2; 00290 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 00291 part += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]); 00292 } 00293 if(nx%2 == 0) { 00294 for ( int iy = 1; iy <= ny/2-1 + iyb; iy++) { 00295 size_t ii = lsd2 - 2 + (iy + iz * ny)* lsd2; 00296 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 00297 part += (x_data[ii+1] - y_data[ii+1])*double(x_data[ii+1] - y_data[ii+1]); 00298 } 00299 00300 } 00301 part *= 2; 00302 part += (x_data[0] - y_data[0])*double(x_data[0] - y_data[0]); 00303 if(ny%2 == 0) { 00304 int ii = (ny/2 + iz * ny)* lsd2; 00305 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 00306 } 00307 if(nx%2 == 0) { 00308 int ii = lsd2 - 2 + (0 + iz * ny)* lsd2; 00309 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 00310 if(ny%2 == 0) { 00311 int ii = lsd2 - 2 +(ny/2 + iz * ny)* lsd2; 00312 part += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 00313 } 00314 } 00315 result += part; 00316 } 00317 n = (float)nx*(float)ny*(float)nz*(float)nx*(float)ny*(float)nz; 00318 00319 }else{ //This 3D code is incorrect, but it is the best I can do now 01/09/06 PAP 00320 int ky, kz; 00321 int ny2 = ny/2; int nz2 = nz/2; 00322 for ( int iz = 0; iz <= nz-1; iz++) { 00323 if(iz>nz2) kz=iz-nz; else kz=iz; 00324 for ( int iy = 0; iy <= ny-1; iy++) { 00325 if(iy>ny2) ky=iy-ny; else ky=iy; 00326 for ( int ix = 0; ix <= lsd2-1; ix++) { 00327 // Skip Friedel related values 00328 if(ix>0 || (kz>=0 && (ky>=0 || kz!=0))) { 00329 size_t ii = ix + (iy + iz * ny)* lsd2; 00330 result += (x_data[ii] - y_data[ii])*double(x_data[ii] - y_data[ii]); 00331 } 00332 } 00333 } 00334 } 00335 n = ((float)nx*(float)ny*(float)nz*(float)nx*(float)ny*(float)nz)/2.0f; 00336 } 00337 } else { // real space 00338 size_t totsize = image->get_xsize()*image->get_ysize()*image->get_zsize(); 00339 if (params.has_key("mask")) { 00340 EMData* mask; 00341 mask = params["mask"]; 00342 const float *const dm = mask->get_const_data(); 00343 for (size_t i = 0; i < totsize; i++) { 00344 if (dm[i] > 0.5) { 00345 double temp = x_data[i]- y_data[i]; 00346 result += temp*temp; 00347 n++; 00348 } 00349 } 00350 } 00351 else if (zeromask) { 00352 n=0; 00353 for (size_t i = 0; i < totsize; i++) { 00354 if (x_data[i]==0 || y_data[i]==0) continue; 00355 double temp = x_data[i]- y_data[i]; 00356 result += temp*temp; 00357 n++; 00358 } 00359 00360 } 00361 else { 00362 for (size_t i = 0; i < totsize; i++) { 00363 double temp = x_data[i]- y_data[i]; 00364 result += temp*temp; 00365 } 00366 n = (float)totsize; 00367 } 00368 } 00369 result/=n; 00370 00371 EXITFUNC; 00372 if (with->has_attr("deleteme")) delete with; 00373 float ret = (float)result; 00374 if (!Util::goodf(&ret)) return FLT_MAX; 00375 return ret; 00376 }
|
|
Implements EMAN::Cmp. Definition at line 240 of file cmp.h. 00241 { 00242 return "Squared Euclidean distance (sum(a - b)^2)/n."; 00243 }
|
|
Get the Cmp's name. Each Cmp is identified by a unique name.
Implements EMAN::Cmp. Definition at line 235 of file cmp.h. 00236 {
00237 return NAME;
00238 }
|
|
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 250 of file cmp.h. References EMAN::TypeDict::put(). 00251 { 00252 TypeDict d; 00253 d.put("mask", EMObject::EMDATA, "image mask"); 00254 d.put("zeromask", EMObject::INT, "If set, zero pixels in either image will be excluded from the statistics"); 00255 d.put("normto",EMObject::INT,"If set, 'with' is normalized to 'this' before computing the distance"); 00256 return d; 00257 }
|
|
Definition at line 245 of file cmp.h. 00246 { 00247 return new SqEuclideanCmp(); 00248 }
|
|
|