#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.
IterationAverager::IterationAverager | ( | ) |
Definition at line 366 of file averager.cpp.
Referenced by NEW().
00366 : nimg(0) 00367 { 00368 00369 }
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 371 of file averager.cpp.
References EMAN::EMData::get_data(), get_name(), EMAN::EMUtil::is_same_size(), LOGERR, nimg, EMAN::Averager::result, EMAN::EMData::set_size(), and sigma_image.
00372 { 00373 if (!image) { 00374 return; 00375 } 00376 00377 if (nimg >= 1 && !EMUtil::is_same_size(image, result)) { 00378 LOGERR("%sAverager can only process same-size Image", 00379 get_name().c_str()); 00380 return; 00381 } 00382 00383 nimg++; 00384 00385 int nx = image->get_xsize(); 00386 int ny = image->get_ysize(); 00387 int nz = image->get_zsize(); 00388 size_t image_size = nx * ny * nz; 00389 00390 if (nimg == 1) { 00391 result = new EMData(); 00392 result->set_size(nx, ny, nz); 00393 sigma_image = new EMData(); 00394 sigma_image->set_size(nx, ny, nz); 00395 } 00396 00397 float *image_data = image->get_data(); 00398 float *result_data = result->get_data(); 00399 float *sigma_image_data = sigma_image->get_data(); 00400 00401 for (size_t j = 0; j < image_size; j++) { 00402 float f = image_data[j]; 00403 result_data[j] += f; 00404 sigma_image_data[j] += f * f; 00405 } 00406 00407 00408 }
EMData * IterationAverager::finish | ( | ) | [virtual] |
Finish up the averaging and return the result.
Implements EMAN::Averager.
Definition at line 410 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().
00411 { 00412 if (nimg < 1) { 00413 return result; 00414 } 00415 00416 int nx = result->get_xsize(); 00417 int ny = result->get_ysize(); 00418 int nz = result->get_zsize(); 00419 size_t image_size = nx * ny * nz; 00420 00421 float *result_data = result->get_data(); 00422 float *sigma_image_data = sigma_image->get_data(); 00423 00424 for (size_t j = 0; j < image_size; j++) { 00425 result_data[j] /= nimg; 00426 float f1 = sigma_image_data[j] / nimg; 00427 float f2 = result_data[j]; 00428 sigma_image_data[j] = sqrt(f1 - f2 * f2) / sqrt((float)nimg); 00429 } 00430 00431 result->update(); 00432 sigma_image->update(); 00433 00434 result->append_image("iter.hed"); 00435 float sigma = sigma_image->get_attr("sigma"); 00436 float *sigma_image_data2 = sigma_image->get_data(); 00437 float *result_data2 = result->get_data(); 00438 float *d2 = new float[nx * ny]; 00439 size_t sec_size = nx * ny * sizeof(float); 00440 00441 memcpy(d2, result_data2, sec_size); 00442 memcpy(sigma_image_data2, result_data2, sec_size); 00443 00444 printf("Iter sigma=%f\n", sigma); 00445 00446 for (int k = 0; k < 1000; k++) { 00447 for (int i = 1; i < nx - 1; i++) { 00448 for (int j = 1; j < ny - 1; j++) { 00449 int l = i + j * nx; 00450 float c1 = (d2[l - 1] + d2[l + 1] + d2[l - nx] + d2[l + nx]) / 4.0f - d2[l]; 00451 float c2 = fabs(result_data2[l] - sigma_image_data2[l]) / sigma; 00452 result_data2[l] += c1 * Util::eman_erfc(c2) / 100.0f; 00453 } 00454 } 00455 00456 memcpy(d2, result_data2, sec_size); 00457 } 00458 00459 if( d2 ) 00460 { 00461 delete[]d2; 00462 d2 = 0; 00463 } 00464 00465 sigma_image->update(); 00466 if( sigma_image ) 00467 { 00468 delete sigma_image; 00469 sigma_image = 0; 00470 } 00471 00472 result->update(); 00473 result->append_image("iter.hed"); 00474 00475 00476 return result; 00477 }
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 264 of file averager.h.
References NAME.
Referenced by add_image().
00265 { 00266 return NAME; 00267 }
static Averager* EMAN::IterationAverager::NEW | ( | ) | [inline, static] |
Definition at line 274 of file averager.h.
References IterationAverager().
00275 { 00276 return new IterationAverager(); 00277 }
const string IterationAverager::NAME = "iteration" [static] |
int EMAN::IterationAverager::nimg [private] |
EMData* EMAN::IterationAverager::sigma_image [private] |