#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 389 of file averager.h.
|
Definition at line 603 of file averager.cpp. 00603 : nimg(0) 00604 { 00605 00606 }
|
|
To add an image to the Averager. This image will be averaged in this function.
Implements EMAN::Averager. Definition at line 608 of file averager.cpp. References EMAN::EMData::copy_head(), 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(). 00609 { 00610 if (!image) { 00611 return; 00612 } 00613 00614 if (nimg >= 1 && !EMUtil::is_same_size(image, result)) { 00615 LOGERR("%sAverager can only process same-size Image", 00616 get_name().c_str()); 00617 return; 00618 } 00619 00620 nimg++; 00621 00622 int nx = image->get_xsize(); 00623 int ny = image->get_ysize(); 00624 int nz = image->get_zsize(); 00625 size_t image_size = (size_t)nx * ny * nz; 00626 00627 if (nimg == 1) { 00628 result = image->copy_head(); 00629 result->set_size(nx, ny, nz); 00630 sigma_image = image->copy_head(); 00631 sigma_image->set_size(nx, ny, nz); 00632 } 00633 00634 float *image_data = image->get_data(); 00635 float *result_data = result->get_data(); 00636 float *sigma_image_data = sigma_image->get_data(); 00637 00638 for (size_t j = 0; j < image_size; ++j) { 00639 float f = image_data[j]; 00640 result_data[j] += f; 00641 sigma_image_data[j] += f * f; 00642 } 00643 00644 00645 }
|
|
Finish up the averaging and return the result.
Implements EMAN::Averager. Definition at line 647 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(). 00648 { 00649 if (nimg < 1) { 00650 return result; 00651 } 00652 00653 int nx = result->get_xsize(); 00654 int ny = result->get_ysize(); 00655 int nz = result->get_zsize(); 00656 size_t image_size = (size_t)nx * ny * nz; 00657 00658 float *result_data = result->get_data(); 00659 float *sigma_image_data = sigma_image->get_data(); 00660 00661 for (size_t j = 0; j < image_size; ++j) { 00662 result_data[j] /= nimg; 00663 float f1 = sigma_image_data[j] / nimg; 00664 float f2 = result_data[j]; 00665 sigma_image_data[j] = sqrt(f1 - f2 * f2) / sqrt((float)nimg); 00666 } 00667 00668 result->update(); 00669 sigma_image->update(); 00670 00671 result->append_image("iter.hed"); 00672 float sigma = sigma_image->get_attr("sigma"); 00673 float *sigma_image_data2 = sigma_image->get_data(); 00674 float *result_data2 = result->get_data(); 00675 float *d2 = new float[nx * ny]; 00676 size_t sec_size = nx * ny * sizeof(float); 00677 00678 memcpy(d2, result_data2, sec_size); 00679 memcpy(sigma_image_data2, result_data2, sec_size); 00680 00681 printf("Iter sigma=%f\n", sigma); 00682 00683 for (int k = 0; k < 1000; k++) { 00684 for (int i = 1; i < nx - 1; i++) { 00685 for (int j = 1; j < ny - 1; j++) { 00686 int l = i + j * nx; 00687 float c1 = (d2[l - 1] + d2[l + 1] + d2[l - nx] + d2[l + nx]) / 4.0f - d2[l]; 00688 float c2 = fabs(result_data2[l] - sigma_image_data2[l]) / sigma; 00689 result_data2[l] += c1 * Util::eman_erfc(c2) / 100.0f; 00690 } 00691 } 00692 00693 memcpy(d2, result_data2, sec_size); 00694 } 00695 00696 if( d2 ) 00697 { 00698 delete[]d2; 00699 d2 = 0; 00700 } 00701 00702 sigma_image->update(); 00703 if( sigma_image ) 00704 { 00705 delete sigma_image; 00706 sigma_image = 0; 00707 } 00708 00709 result->update(); 00710 result->append_image("iter.hed"); 00711 00712 00713 return result; 00714 }
|
|
Implements EMAN::Averager. Definition at line 401 of file averager.h. 00402 { 00403 return "Unknown"; 00404 }
|
|
Get the Averager's name. Each Averager is identified by a unique name.
Implements EMAN::Averager. Definition at line 396 of file averager.h. Referenced by add_image(). 00397 {
00398 return NAME;
00399 }
|
|
Definition at line 406 of file averager.h. 00407 { 00408 return new IterationAverager(); 00409 }
|
|
Definition at line 49 of file averager.cpp. |
|
Definition at line 415 of file averager.h. Referenced by add_image(), and finish(). |
|
Definition at line 414 of file averager.h. |