#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 343 of file averager.h.
IterationAverager::IterationAverager | ( | ) |
Definition at line 524 of file averager.cpp.
Referenced by NEW().
00524 : nimg(0) 00525 { 00526 00527 }
void IterationAverager::add_image | ( | EMData * | image | ) | [virtual] |
To add an image to the Averager.
This image will be averaged in this function.
image | The image to be averaged. |
Implements EMAN::Averager.
Definition at line 529 of file averager.cpp.
References EMAN::EMData::copy_head(), EMAN::EMData::get_data(), get_name(), EMAN::EMUtil::is_same_size(), LOGERR, nimg, EMAN::Averager::result, EMAN::EMData::set_size(), and sigma_image.
00530 { 00531 if (!image) { 00532 return; 00533 } 00534 00535 if (nimg >= 1 && !EMUtil::is_same_size(image, result)) { 00536 LOGERR("%sAverager can only process same-size Image", 00537 get_name().c_str()); 00538 return; 00539 } 00540 00541 nimg++; 00542 00543 int nx = image->get_xsize(); 00544 int ny = image->get_ysize(); 00545 int nz = image->get_zsize(); 00546 size_t image_size = (size_t)nx * ny * nz; 00547 00548 if (nimg == 1) { 00549 result = image->copy_head(); 00550 result->set_size(nx, ny, nz); 00551 sigma_image = image->copy_head(); 00552 sigma_image->set_size(nx, ny, nz); 00553 } 00554 00555 float *image_data = image->get_data(); 00556 float *result_data = result->get_data(); 00557 float *sigma_image_data = sigma_image->get_data(); 00558 00559 for (size_t j = 0; j < image_size; ++j) { 00560 float f = image_data[j]; 00561 result_data[j] += f; 00562 sigma_image_data[j] += f * f; 00563 } 00564 00565 00566 }
EMData * IterationAverager::finish | ( | ) | [virtual] |
Finish up the averaging and return the result.
Implements EMAN::Averager.
Definition at line 568 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, EMAN::Averager::result, sigma_image, sqrt(), and EMAN::EMData::update().
00569 { 00570 if (nimg < 1) { 00571 return result; 00572 } 00573 00574 int nx = result->get_xsize(); 00575 int ny = result->get_ysize(); 00576 int nz = result->get_zsize(); 00577 size_t image_size = (size_t)nx * ny * nz; 00578 00579 float *result_data = result->get_data(); 00580 float *sigma_image_data = sigma_image->get_data(); 00581 00582 for (size_t j = 0; j < image_size; ++j) { 00583 result_data[j] /= nimg; 00584 float f1 = sigma_image_data[j] / nimg; 00585 float f2 = result_data[j]; 00586 sigma_image_data[j] = sqrt(f1 - f2 * f2) / sqrt((float)nimg); 00587 } 00588 00589 result->update(); 00590 sigma_image->update(); 00591 00592 result->append_image("iter.hed"); 00593 float sigma = sigma_image->get_attr("sigma"); 00594 float *sigma_image_data2 = sigma_image->get_data(); 00595 float *result_data2 = result->get_data(); 00596 float *d2 = new float[nx * ny]; 00597 size_t sec_size = nx * ny * sizeof(float); 00598 00599 memcpy(d2, result_data2, sec_size); 00600 memcpy(sigma_image_data2, result_data2, sec_size); 00601 00602 printf("Iter sigma=%f\n", sigma); 00603 00604 for (int k = 0; k < 1000; k++) { 00605 for (int i = 1; i < nx - 1; i++) { 00606 for (int j = 1; j < ny - 1; j++) { 00607 int l = i + j * nx; 00608 float c1 = (d2[l - 1] + d2[l + 1] + d2[l - nx] + d2[l + nx]) / 4.0f - d2[l]; 00609 float c2 = fabs(result_data2[l] - sigma_image_data2[l]) / sigma; 00610 result_data2[l] += c1 * Util::eman_erfc(c2) / 100.0f; 00611 } 00612 } 00613 00614 memcpy(d2, result_data2, sec_size); 00615 } 00616 00617 if( d2 ) 00618 { 00619 delete[]d2; 00620 d2 = 0; 00621 } 00622 00623 sigma_image->update(); 00624 if( sigma_image ) 00625 { 00626 delete sigma_image; 00627 sigma_image = 0; 00628 } 00629 00630 result->update(); 00631 result->append_image("iter.hed"); 00632 00633 00634 return result; 00635 }
string EMAN::IterationAverager::get_desc | ( | ) | const [inline, virtual] |
string EMAN::IterationAverager::get_name | ( | ) | const [inline, virtual] |
Get the Averager's name.
Each Averager is identified by a unique name.
Implements EMAN::Averager.
Definition at line 350 of file averager.h.
References NAME.
Referenced by add_image().
00351 { 00352 return NAME; 00353 }
static Averager* EMAN::IterationAverager::NEW | ( | ) | [inline, static] |
Definition at line 360 of file averager.h.
References IterationAverager().
00361 { 00362 return new IterationAverager(); 00363 }
const string IterationAverager::NAME = "iteration" [static] |
int EMAN::IterationAverager::nimg [private] |
EMData* EMAN::IterationAverager::sigma_image [private] |