EMAN::ImageAverager Class Reference

ImageAverager averages a list of images. More...

#include <averager.h>

Inheritance diagram for EMAN::ImageAverager:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ImageAverager ()
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
TypeDict get_param_types () const
 Get Averager parameter information in a dictionary.
virtual void mult (const float &)
 Multiply the result image by some floating point constant This is useful when weighting the input images prior to calling add_image - a situation where it is likely you want to divide by the sum of the weights.

Static Public Member Functions

static AveragerNEW ()

Static Public Attributes

static const string NAME = "mean"

Private Attributes

EMDatasigma_image
int * nimg_n0
int ignore0
int nimg

Detailed Description

ImageAverager averages a list of images.

It optionally makes a sigma image.

Parameters:
sigma sigma value
ignore0 if set, ignore zero value pixels

Definition at line 170 of file averager.h.


Constructor & Destructor Documentation

ImageAverager::ImageAverager (  ) 

Definition at line 186 of file averager.cpp.

Referenced by NEW().

00187         : sigma_image(0), nimg_n0(0), ignore0(0), nimg(0)
00188 {
00189 
00190 }


Member Function Documentation

void ImageAverager::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 192 of file averager.cpp.

References EMAN::EMData::get_data(), get_name(), ignore0, EMAN::EMUtil::is_same_size(), LOGERR, nimg, nimg_n0, nx, ny, EMAN::Averager::params, EMAN::Averager::result, EMAN::Dict::set_default(), EMAN::EMData::set_size(), and sigma_image.

00193 {
00194         if (!image) {
00195                 return;
00196         }
00197 
00198         if (nimg >= 1 && !EMUtil::is_same_size(image, result)) {
00199                 LOGERR("%sAverager can only process same-size Image",
00200                            get_name().c_str());
00201                 return;
00202         }
00203 
00204         nimg++;
00205 
00206         int nx = image->get_xsize();
00207         int ny = image->get_ysize();
00208         int nz = image->get_zsize();
00209         size_t image_size = (size_t)nx * ny * nz;
00210 
00211         if (nimg == 1) {
00212                 result = new EMData();
00213                 result->set_size(nx, ny, nz);
00214                 sigma_image = params.set_default("sigma", (EMData*)0);
00215                 ignore0 = params["ignore0"];
00216 
00217                 nimg_n0 = new int[image_size];
00218                 for (size_t i = 0; i < image_size; ++i) {
00219                         nimg_n0[i] = 0;
00220                 }
00221         }
00222 
00223         float *result_data = result->get_data();
00224         float *sigma_image_data = 0;
00225         if (sigma_image) {
00226                 sigma_image->set_size(nx, ny, nz);
00227                 sigma_image_data = sigma_image->get_data();
00228         }
00229 
00230         float * image_data = image->get_data();
00231 
00232         if (!ignore0) {
00233                 for (size_t j = 0; j < image_size; ++j) {
00234                         float f = image_data[j];
00235                         result_data[j] += f;
00236                         if (sigma_image_data) {
00237                                 sigma_image_data[j] += f * f;
00238                         }
00239                 }
00240         }
00241         else {
00242                 for (size_t j = 0; j < image_size; ++j) {
00243                         float f = image_data[j];
00244                         if (f) {
00245                                 result_data[j] += f;
00246                                 if (sigma_image_data) {
00247                                         sigma_image_data[j] += f * f;
00248                                 }
00249                                 nimg_n0[j]++;
00250                         }
00251                 }
00252         }
00253 }

EMData * ImageAverager::finish (  )  [virtual]

Finish up the averaging and return the result.

Returns:
The averaged image.

Implements EMAN::Averager.

Definition at line 255 of file averager.cpp.

References EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ignore0, nimg, nimg_n0, EMAN::Averager::result, EMAN::EMData::set_attr(), sigma_image, sqrt(), and EMAN::EMData::update().

00256 {
00257         if (result && nimg > 1) {
00258                 size_t image_size = (size_t)result->get_xsize() * result->get_ysize() * result->get_zsize();
00259                 float * result_data = result->get_data();
00260 
00261                 if (!ignore0) {
00262                         for (size_t j = 0; j < image_size; ++j) {
00263                                 result_data[j] /= nimg;
00264                         }
00265 
00266                         if (sigma_image) {
00267                                 float * sigma_image_data = sigma_image->get_data();
00268 
00269                                 for (size_t j = 0; j < image_size; ++j) {
00270                                         float f1 = sigma_image_data[j] / nimg;
00271                                         float f2 = result_data[j];
00272                                         sigma_image_data[j] = sqrt(f1 - f2 * f2);
00273                                 }
00274 
00275                                 sigma_image->update();
00276                         }
00277                 }
00278                 else {
00279                         for (size_t j = 0; j < image_size; ++j) {
00280                                 result_data[j] /= nimg_n0[j];
00281                         }
00282                         if (sigma_image) {
00283                                 float * sigma_image_data = sigma_image->get_data();
00284 
00285                                 for (size_t j = 0; j < image_size; ++j) {
00286                                         float f1 = sigma_image_data[j] / nimg_n0[j];
00287                                         float f2 = result_data[j];
00288                                         sigma_image_data[j] = sqrt(f1 - f2 * f2);
00289                                 }
00290 
00291                                 sigma_image->update();
00292                         }
00293                 }
00294 
00295                 result->update();
00296 
00297         }
00298         result->set_attr("ptcl_repr",nimg);
00299 
00300         if( nimg_n0 )
00301         {
00302                 delete [] nimg_n0;
00303                 nimg_n0 = 0;
00304         }
00305 
00306         return result;
00307 }

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

Implements EMAN::Averager.

Definition at line 183 of file averager.h.

00184                 {
00185                         return "Simple mean average of images";
00186                 }

string EMAN::ImageAverager::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 178 of file averager.h.

References NAME.

Referenced by add_image().

00179                 {
00180                         return NAME;
00181                 }

TypeDict EMAN::ImageAverager::get_param_types (  )  const [inline, virtual]

Get Averager parameter information in a dictionary.

Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.

Returns:
A dictionary containing the parameter info.

Reimplemented from EMAN::Averager.

Definition at line 193 of file averager.h.

References EMAN::EMObject::EMDATA, EMAN::EMObject::INT, and EMAN::TypeDict::put().

00194                 {
00195                         TypeDict d;
00196                         d.put("sigma", EMObject::EMDATA, "sigma value");
00197                         d.put("ignore0", EMObject::INT, "if set, ignore zero value pixels");
00198                         return d;
00199                 }

virtual void EMAN::ImageAverager::mult ( const float &   )  [inline, virtual]

Multiply the result image by some floating point constant This is useful when weighting the input images prior to calling add_image - a situation where it is likely you want to divide by the sum of the weights.

Hence call mult after all of the weighted images have been added.

Parameters:
s the scaling factor.
Exceptions:
NullPointerException if the EMData pointer (result) is NULL

Reimplemented from EMAN::Averager.

Definition at line 201 of file averager.h.

00201 { }

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

Definition at line 188 of file averager.h.

References ImageAverager().

00189                 {
00190                         return new ImageAverager();
00191                 }


Member Data Documentation

int EMAN::ImageAverager::ignore0 [private]

Definition at line 208 of file averager.h.

Referenced by add_image(), and finish().

const string ImageAverager::NAME = "mean" [static]

Definition at line 203 of file averager.h.

Referenced by get_name().

int EMAN::ImageAverager::nimg [private]

Definition at line 209 of file averager.h.

Referenced by add_image(), and finish().

int* EMAN::ImageAverager::nimg_n0 [private]

Definition at line 207 of file averager.h.

Referenced by add_image(), and finish().

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

Definition at line 206 of file averager.h.

Referenced by add_image(), and finish().


The documentation for this class was generated from the following files:
Generated on Tue Jul 12 13:48:01 2011 for EMAN2 by  doxygen 1.4.7