EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Attributes
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 389 of file averager.h.


Constructor & Destructor Documentation

IterationAverager::IterationAverager ( )

Definition at line 603 of file averager.cpp.

Referenced by NEW().

                                     : nimg(0)
{

}

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:
imageThe image to be averaged.

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

{
        if (!image) {
                return;
        }

        if (nimg >= 1 && !EMUtil::is_same_size(image, result)) {
                LOGERR("%sAverager can only process same-size Image",
                                                         get_name().c_str());
                return;
        }

        nimg++;

        int nx = image->get_xsize();
        int ny = image->get_ysize();
        int nz = image->get_zsize();
        size_t image_size = (size_t)nx * ny * nz;

        if (nimg == 1) {
                result = image->copy_head();
                result->set_size(nx, ny, nz);
                sigma_image = image->copy_head();
                sigma_image->set_size(nx, ny, nz);
        }

        float *image_data = image->get_data();
        float *result_data = result->get_data();
        float *sigma_image_data = sigma_image->get_data();

        for (size_t j = 0; j < image_size; ++j) {
                float f = image_data[j];
                result_data[j] += f;
                sigma_image_data[j] += f * f;
        }


}
EMData * IterationAverager::finish ( ) [virtual]

Finish up the averaging and return the result.

Returns:
The averaged image.

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, EMAN::Averager::result, sigma_image, sqrt(), and EMAN::EMData::update().

{
        if (nimg < 1) {
                return result;
        }

        int nx = result->get_xsize();
        int ny = result->get_ysize();
        int nz = result->get_zsize();
        size_t image_size = (size_t)nx * ny * nz;

        float *result_data = result->get_data();
        float *sigma_image_data = sigma_image->get_data();

        for (size_t j = 0; j < image_size; ++j) {
                result_data[j] /= nimg;
                float f1 = sigma_image_data[j] / nimg;
                float f2 = result_data[j];
                sigma_image_data[j] = sqrt(f1 - f2 * f2) / sqrt((float)nimg);
        }

        result->update();
        sigma_image->update();

        result->append_image("iter.hed");
        float sigma = sigma_image->get_attr("sigma");
        float *sigma_image_data2 = sigma_image->get_data();
        float *result_data2 = result->get_data();
        float *d2 = new float[nx * ny];
        size_t sec_size = nx * ny * sizeof(float);

        memcpy(d2, result_data2, sec_size);
        memcpy(sigma_image_data2, result_data2, sec_size);

        printf("Iter sigma=%f\n", sigma);

        for (int k = 0; k < 1000; k++) {
                for (int i = 1; i < nx - 1; i++) {
                        for (int j = 1; j < ny - 1; j++) {
                                int l = i + j * nx;
                                float c1 = (d2[l - 1] + d2[l + 1] + d2[l - nx] + d2[l + nx]) / 4.0f - d2[l];
                                float c2 = fabs(result_data2[l] - sigma_image_data2[l]) / sigma;
                                result_data2[l] += c1 * Util::eman_erfc(c2) / 100.0f;
                        }
                }

                memcpy(d2, result_data2, sec_size);
        }

        if( d2 )
        {
                delete[]d2;
                d2 = 0;
        }

        sigma_image->update();
        if( sigma_image )
        {
                delete sigma_image;
                sigma_image = 0;
        }

        result->update();
        result->append_image("iter.hed");


        return result;
}
string EMAN::IterationAverager::get_desc ( ) const [inline, virtual]

Implements EMAN::Averager.

Definition at line 401 of file averager.h.

                {
                        return "Unknown";
                }
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 396 of file averager.h.

References NAME.

Referenced by add_image().

                {
                        return NAME;
                }
static Averager* EMAN::IterationAverager::NEW ( ) [inline, static]

Definition at line 406 of file averager.h.

References IterationAverager().

                {
                        return new IterationAverager();
                }

Member Data Documentation

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

Definition at line 411 of file averager.h.

Referenced by get_name().

Definition at line 415 of file averager.h.

Referenced by add_image(), and finish().

Definition at line 414 of file averager.h.

Referenced by finish().


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