#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 | |
| Averager * | NEW () |
Static Public Attributes | |
| const string | NAME = "iteration" |
Private Attributes | |
| EMData * | sigma_image |
| int | nimg |
Definition at line 302 of file averager.h.
|
|
Definition at line 467 of file averager.cpp. 00467 : nimg(0) 00468 { 00469 00470 }
|
|
|
To add an image to the Averager. This image will be averaged in this function.
Implements EMAN::Averager. Definition at line 472 of file averager.cpp. References EMAN::EMData::get_data(), get_name(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::EMUtil::is_same_size(), LOGERR, nimg, nx, ny, and EMAN::EMData::set_size(). 00473 {
00474 if (!image) {
00475 return;
00476 }
00477
00478 if (nimg >= 1 && !EMUtil::is_same_size(image, result)) {
00479 LOGERR("%sAverager can only process same-size Image",
00480 get_name().c_str());
00481 return;
00482 }
00483
00484 nimg++;
00485
00486 int nx = image->get_xsize();
00487 int ny = image->get_ysize();
00488 int nz = image->get_zsize();
00489 size_t image_size = (size_t)nx * ny * nz;
00490
00491 if (nimg == 1) {
00492 result = new EMData();
00493 result->set_size(nx, ny, nz);
00494 sigma_image = new EMData();
00495 sigma_image->set_size(nx, ny, nz);
00496 }
00497
00498 float *image_data = image->get_data();
00499 float *result_data = result->get_data();
00500 float *sigma_image_data = sigma_image->get_data();
00501
00502 for (size_t j = 0; j < image_size; ++j) {
00503 float f = image_data[j];
00504 result_data[j] += f;
00505 sigma_image_data[j] += f * f;
00506 }
00507
00508
00509 }
|
|
|
Finish up the averaging and return the result.
Implements EMAN::Averager. Definition at line 511 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, nx, ny, sqrt(), and EMAN::EMData::update(). 00512 {
00513 if (nimg < 1) {
00514 return result;
00515 }
00516
00517 int nx = result->get_xsize();
00518 int ny = result->get_ysize();
00519 int nz = result->get_zsize();
00520 size_t image_size = (size_t)nx * ny * nz;
00521
00522 float *result_data = result->get_data();
00523 float *sigma_image_data = sigma_image->get_data();
00524
00525 for (size_t j = 0; j < image_size; ++j) {
00526 result_data[j] /= nimg;
00527 float f1 = sigma_image_data[j] / nimg;
00528 float f2 = result_data[j];
00529 sigma_image_data[j] = sqrt(f1 - f2 * f2) / sqrt((float)nimg);
00530 }
00531
00532 result->update();
00533 sigma_image->update();
00534
00535 result->append_image("iter.hed");
00536 float sigma = sigma_image->get_attr("sigma");
00537 float *sigma_image_data2 = sigma_image->get_data();
00538 float *result_data2 = result->get_data();
00539 float *d2 = new float[nx * ny];
00540 size_t sec_size = nx * ny * sizeof(float);
00541
00542 memcpy(d2, result_data2, sec_size);
00543 memcpy(sigma_image_data2, result_data2, sec_size);
00544
00545 printf("Iter sigma=%f\n", sigma);
00546
00547 for (int k = 0; k < 1000; k++) {
00548 for (int i = 1; i < nx - 1; i++) {
00549 for (int j = 1; j < ny - 1; j++) {
00550 int l = i + j * nx;
00551 float c1 = (d2[l - 1] + d2[l + 1] + d2[l - nx] + d2[l + nx]) / 4.0f - d2[l];
00552 float c2 = fabs(result_data2[l] - sigma_image_data2[l]) / sigma;
00553 result_data2[l] += c1 * Util::eman_erfc(c2) / 100.0f;
00554 }
00555 }
00556
00557 memcpy(d2, result_data2, sec_size);
00558 }
00559
00560 if( d2 )
00561 {
00562 delete[]d2;
00563 d2 = 0;
00564 }
00565
00566 sigma_image->update();
00567 if( sigma_image )
00568 {
00569 delete sigma_image;
00570 sigma_image = 0;
00571 }
00572
00573 result->update();
00574 result->append_image("iter.hed");
00575
00576
00577 return result;
00578 }
|
|
|
Implements EMAN::Averager. Definition at line 314 of file averager.h. 00315 {
00316 return "Unknown";
00317 }
|
|
|
Get the Averager's name. Each Averager is identified by a unique name.
Implements EMAN::Averager. Definition at line 309 of file averager.h. Referenced by add_image(). 00310 {
00311 return NAME;
00312 }
|
|
|
Definition at line 319 of file averager.h. 00320 {
00321 return new IterationAverager();
00322 }
|
|
|
Definition at line 48 of file averager.cpp. |
|
|
Definition at line 328 of file averager.h. Referenced by add_image(), and finish(). |
|
|
Definition at line 327 of file averager.h. |
1.3.9.1