Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

EMAN::IterationAverager Class Reference

IterationAverager averages images by doing the smoothing iteration. More...

#include <averager.h>

Inheritance diagram for EMAN::IterationAverager:

Inheritance graph
[legend]
Collaboration diagram for EMAN::IterationAverager:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 IterationAverager ()
void add_image (EMData *image)
 To add an image to the Averager.
EMDatafinish ()
 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 AveragerNEW ()

Static Public Attributes

static const string NAME = "iteration"

Private Attributes

EMDatasigma_image
int nimg

Detailed Description

IterationAverager averages images by doing the smoothing iteration.

Definition at line 257 of file averager.h.


Constructor & Destructor Documentation

IterationAverager::IterationAverager  ) 
 

Definition at line 362 of file averager.cpp.

Referenced by NEW().

00362                                      : nimg(0)
00363 {
00364 
00365 }


Member Function Documentation

void IterationAverager::add_image EMData image  )  [virtual]
 

To add an image to the Averager.

This image will be averaged in this function.

Parameters:
image The image to be averaged.

Implements EMAN::Averager.

Definition at line 367 of file averager.cpp.

References EMAN::EMData::get_data(), get_name(), EMAN::EMUtil::is_same_size(), LOGERR, nimg, and EMAN::EMData::set_size().

00368 {
00369         if (!image) {
00370                 return;
00371         }
00372 
00373         if (nimg >= 1 && !EMUtil::is_same_size(image, result)) {
00374                 LOGERR("%sAverager can only process same-size Image",
00375                                                          get_name().c_str());
00376                 return;
00377         }
00378 
00379         nimg++;
00380 
00381         int nx = image->get_xsize();
00382         int ny = image->get_ysize();
00383         int nz = image->get_zsize();
00384         size_t image_size = nx * ny * nz;
00385 
00386         if (nimg == 1) {
00387                 result = new EMData();
00388                 result->set_size(nx, ny, nz);
00389                 sigma_image = new EMData();
00390                 sigma_image->set_size(nx, ny, nz);
00391         }
00392 
00393         float *image_data = image->get_data();
00394         float *result_data = result->get_data();
00395         float *sigma_image_data = sigma_image->get_data();
00396 
00397         for (size_t j = 0; j < image_size; j++) {
00398                 float f = image_data[j];
00399                 result_data[j] += f;
00400                 sigma_image_data[j] += f * f;
00401         }
00402 
00403 
00404 }

EMData * IterationAverager::finish  )  [virtual]
 

Finish up the averaging and return the result.

Returns:
The averaged image.

Implements EMAN::Averager.

Definition at line 406 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().

00407 {
00408         if (nimg < 1) {
00409                 return result;
00410         }
00411 
00412         int nx = result->get_xsize();
00413         int ny = result->get_ysize();
00414         int nz = result->get_zsize();
00415         size_t image_size = nx * ny * nz;
00416 
00417         float *result_data = result->get_data();
00418         float *sigma_image_data = sigma_image->get_data();
00419 
00420         for (size_t j = 0; j < image_size; j++) {
00421                 result_data[j] /= nimg;
00422                 float f1 = sigma_image_data[j] / nimg;
00423                 float f2 = result_data[j];
00424                 sigma_image_data[j] = sqrt(f1 - f2 * f2) / sqrt((float)nimg);
00425         }
00426 
00427         result->update();
00428         sigma_image->update();
00429 
00430         result->append_image("iter.hed");
00431         float sigma = sigma_image->get_attr("sigma");
00432         float *sigma_image_data2 = sigma_image->get_data();
00433         float *result_data2 = result->get_data();
00434         float *d2 = new float[nx * ny];
00435         size_t sec_size = nx * ny * sizeof(float);
00436 
00437         memcpy(d2, result_data2, sec_size);
00438         memcpy(sigma_image_data2, result_data2, sec_size);
00439 
00440         printf("Iter sigma=%f\n", sigma);
00441 
00442         for (int k = 0; k < 1000; k++) {
00443                 for (int i = 1; i < nx - 1; i++) {
00444                         for (int j = 1; j < ny - 1; j++) {
00445                                 int l = i + j * nx;
00446                                 float c1 = (d2[l - 1] + d2[l + 1] + d2[l - nx] + d2[l + nx]) / 4.0f - d2[l];
00447                                 float c2 = fabs(result_data2[l] - sigma_image_data2[l]) / sigma;
00448                                 result_data2[l] += c1 * Util::eman_erfc(c2) / 100.0f;
00449                         }
00450                 }
00451 
00452                 memcpy(d2, result_data2, sec_size);
00453         }
00454 
00455         if( d2 )
00456         {
00457                 delete[]d2;
00458                 d2 = 0;
00459         }
00460 
00461         sigma_image->update();
00462         if( sigma_image )
00463         {
00464                 delete sigma_image;
00465                 sigma_image = 0;
00466         }
00467 
00468         result->update();
00469         result->append_image("iter.hed");
00470 
00471 
00472         return result;
00473 }

string EMAN::IterationAverager::get_desc  )  const [inline, virtual]
 

Implements EMAN::Averager.

Definition at line 269 of file averager.h.

00270                 {
00271                         return "Unknown";
00272                 }

string EMAN::IterationAverager::get_name  )  const [inline, virtual]
 

Get the Averager's name.

Each Averager is identified by a unique name.

Returns:
The Averager's 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                 }


Member Data Documentation

const string IterationAverager::NAME = "iteration" [static]
 

Definition at line 279 of file averager.h.

Referenced by get_name().

int EMAN::IterationAverager::nimg [private]
 

Definition at line 283 of file averager.h.

Referenced by add_image(), and finish().

EMData* EMAN::IterationAverager::sigma_image [private]
 

Definition at line 282 of file averager.h.


The documentation for this class was generated from the following files:
Generated on Mon Jul 19 13:05:52 2010 for EMAN2 by  doxygen 1.4.4