#include <averager.h>
Inheritance diagram for EMAN::IterationAverager:
Public Member Functions | |
IterationAverager () | |
void | add_image (EMData *image) |
To add an image to the Averager. | |
EMData * | finish () |
Finish up the averaging and return the result. | |
string | get_name () const |
Get the Averager's name. | |
string | get_desc () const |
Static Public Member Functions | |
static Averager * | NEW () |
Static Public Attributes | |
static const string | NAME = "iteration" |
Private Attributes | |
EMData * | sigma_image |
int | nimg |
Definition at line 257 of file averager.h.
|
Definition at line 360 of file averager.cpp. Referenced by NEW(). 00360 : nimg(0) 00361 { 00362 00363 }
|
|
To add an image to the Averager. This image will be averaged in this function.
Implements EMAN::Averager. Definition at line 365 of file averager.cpp. References EMAN::EMData::get_data(), get_name(), EMAN::EMUtil::is_same_size(), LOGERR, nimg, and EMAN::EMData::set_size(). 00366 { 00367 if (!image) { 00368 return; 00369 } 00370 00371 if (nimg >= 1 && !EMUtil::is_same_size(image, result)) { 00372 LOGERR("%sAverager can only process same-size Image", 00373 get_name().c_str()); 00374 return; 00375 } 00376 00377 nimg++; 00378 00379 int nx = image->get_xsize(); 00380 int ny = image->get_ysize(); 00381 int nz = image->get_zsize(); 00382 size_t image_size = nx * ny * nz; 00383 00384 if (nimg == 1) { 00385 result = new EMData(); 00386 result->set_size(nx, ny, nz); 00387 sigma_image = new EMData(); 00388 sigma_image->set_size(nx, ny, nz); 00389 } 00390 00391 float *image_data = image->get_data(); 00392 float *result_data = result->get_data(); 00393 float *sigma_image_data = sigma_image->get_data(); 00394 00395 for (size_t j = 0; j < image_size; j++) { 00396 float f = image_data[j]; 00397 result_data[j] += f; 00398 sigma_image_data[j] += f * f; 00399 } 00400 00401 00402 }
|
|
Finish up the averaging and return the result.
Implements EMAN::Averager. Definition at line 404 of file averager.cpp. References EMAN::EMData::append_image(), EMAN::Util::eman_erfc(), EMAN::EMData::get_attr(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), nimg, sqrt(), and EMAN::EMData::update(). 00405 { 00406 if (nimg < 1) { 00407 return result; 00408 } 00409 00410 int nx = result->get_xsize(); 00411 int ny = result->get_ysize(); 00412 int nz = result->get_zsize(); 00413 size_t image_size = nx * ny * nz; 00414 00415 float *result_data = result->get_data(); 00416 float *sigma_image_data = sigma_image->get_data(); 00417 00418 for (size_t j = 0; j < image_size; j++) { 00419 result_data[j] /= nimg; 00420 float f1 = sigma_image_data[j] / nimg; 00421 float f2 = result_data[j]; 00422 sigma_image_data[j] = sqrt(f1 - f2 * f2) / sqrt((float)nimg); 00423 } 00424 00425 result->update(); 00426 sigma_image->update(); 00427 00428 result->append_image("iter.hed"); 00429 float sigma = sigma_image->get_attr("sigma"); 00430 float *sigma_image_data2 = sigma_image->get_data(); 00431 float *result_data2 = result->get_data(); 00432 float *d2 = new float[nx * ny]; 00433 size_t sec_size = nx * ny * sizeof(float); 00434 00435 memcpy(d2, result_data2, sec_size); 00436 memcpy(sigma_image_data2, result_data2, sec_size); 00437 00438 printf("Iter sigma=%f\n", sigma); 00439 00440 for (int k = 0; k < 1000; k++) { 00441 for (int i = 1; i < nx - 1; i++) { 00442 for (int j = 1; j < ny - 1; j++) { 00443 int l = i + j * nx; 00444 float c1 = (d2[l - 1] + d2[l + 1] + d2[l - nx] + d2[l + nx]) / 4.0f - d2[l]; 00445 float c2 = fabs(result_data2[l] - sigma_image_data2[l]) / sigma; 00446 result_data2[l] += c1 * Util::eman_erfc(c2) / 100.0f; 00447 } 00448 } 00449 00450 memcpy(d2, result_data2, sec_size); 00451 } 00452 00453 if( d2 ) 00454 { 00455 delete[]d2; 00456 d2 = 0; 00457 } 00458 00459 sigma_image->update(); 00460 if( sigma_image ) 00461 { 00462 delete sigma_image; 00463 sigma_image = 0; 00464 } 00465 00466 result->update(); 00467 result->append_image("iter.hed"); 00468 00469 00470 return result; 00471 }
|
|
Implements EMAN::Averager. Definition at line 269 of file averager.h.
|
|
Get the Averager's name. Each Averager is identified by a unique name.
Implements EMAN::Averager. Definition at line 264 of file averager.h. References NAME. Referenced by add_image(). 00265 { 00266 return NAME; 00267 }
|
|
Definition at line 274 of file averager.h. References IterationAverager(). 00275 { 00276 return new IterationAverager(); 00277 }
|
|
Definition at line 279 of file averager.h. Referenced by get_name(). |
|
Definition at line 283 of file averager.h. Referenced by add_image(), and finish(). |
|
Definition at line 282 of file averager.h. |