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:

[legend]
Collaboration diagram for EMAN::IterationAverager:
[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

AveragerNEW ()

Static Public Attributes

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 360 of file averager.cpp.

00360                                      : nimg(0)
00361 {
00362 
00363 }


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

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

EMData * IterationAverager::finish  )  [virtual]
 

Finish up the averaging and return the result.

Returns:
The averaged image.

Implements EMAN::Averager.

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

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

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.

Referenced by add_image().

00265                 {
00266                         return NAME;
00267                 }

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

Definition at line 274 of file averager.h.

00275                 {
00276                         return new IterationAverager();
00277                 }


Member Data Documentation

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

Definition at line 47 of file averager.cpp.

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 Fri Apr 30 15:39:13 2010 for EMAN2 by  doxygen 1.3.9.1