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 ()

Private Attributes

EMDatasigma_image
int nimg


Detailed Description

IterationAverager averages images by doing the smoothing iteration.

Definition at line 253 of file averager.h.


Constructor & Destructor Documentation

IterationAverager::IterationAverager (  ) 

Definition at line 350 of file averager.cpp.

Referenced by NEW().

00350                                      : nimg(0)
00351 {
00352 
00353 }


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 355 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, and EMAN::EMData::set_size().

00356 {
00357         if (!image) {
00358                 return;
00359         }
00360 
00361         if (nimg >= 1 && !EMUtil::is_same_size(image, result)) {
00362                 LOGERR("%sAverager can only process same-size Image",
00363                                                          get_name().c_str());
00364                 return;
00365         }
00366 
00367         nimg++;
00368 
00369         int nx = image->get_xsize();
00370         int ny = image->get_ysize();
00371         int nz = image->get_zsize();
00372         size_t image_size = nx * ny * nz;
00373 
00374         if (nimg == 1) {
00375                 result = new EMData();
00376                 result->set_size(nx, ny, nz);
00377                 sigma_image = new EMData();
00378                 sigma_image->set_size(nx, ny, nz);
00379         }
00380 
00381         float *image_data = image->get_data();
00382         float *result_data = result->get_data();
00383         float *sigma_image_data = sigma_image->get_data();
00384 
00385         for (size_t j = 0; j < image_size; j++) {
00386                 float f = image_data[j];
00387                 result_data[j] += f;
00388                 sigma_image_data[j] += f * f;
00389         }
00390 
00391 
00392 }

EMData * IterationAverager::finish (  )  [virtual]

Finish up the averaging and return the result.

Returns:
The averaged image.

Implements EMAN::Averager.

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

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

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 260 of file averager.h.

Referenced by add_image().

00261                 {
00262                         return "iteration";
00263                 }

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

Implements EMAN::Averager.

Definition at line 265 of file averager.h.

00266                 {
00267                         return "Unknown";
00268                 }

static Averager* EMAN::IterationAverager::NEW (  )  [inline, static]

Definition at line 270 of file averager.h.

References IterationAverager().

00271                 {
00272                         return new IterationAverager();
00273                 }


Member Data Documentation

Definition at line 275 of file averager.h.

Definition at line 276 of file averager.h.

Referenced by add_image(), and finish().


The documentation for this class was generated from the following files:

Generated on Sat Nov 21 02:20:15 2009 for EMAN2 by  doxygen 1.5.6