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

EMAN::FourierWeightAverager Class Reference

FourierWeightAverager makes an average of a set of images in Fourier space using a per-image radial weight. More...

#include <averager.h>

Inheritance diagram for EMAN::FourierWeightAverager:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

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

Static Public Member Functions

AveragerNEW ()

Static Public Attributes

const string NAME = "weightedfourier"

Private Attributes

EMDatanormimage
int freenorm
int nimg

Detailed Description

FourierWeightAverager makes an average of a set of images in Fourier space using a per-image radial weight.

The provided XYData object for each inserted image should range from x=0 - 0.5*sqrt(2), and contains the radial weights from 0 - Nyquist at the point. If the x range is insufficient, values will be clamped at the ends of the available x-range. 2-D Images only, but will work with rectangular images.

Parameters:
normimage After finish() will contain the sum of the weights in each Fourier location. Size must be ((nx+1)/2,y)

Definition at line 218 of file averager.h.


Constructor & Destructor Documentation

FourierWeightAverager::FourierWeightAverager  ) 
 

Definition at line 302 of file averager.cpp.

00303         : normimage(0), freenorm(0), nimg(0)
00304 {
00305 
00306 }


Member Function Documentation

void FourierWeightAverager::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 308 of file averager.cpp.

References EMAN::EMData::do_fft(), freenorm, EMAN::EMData::get_attr(), EMAN::EMData::get_complex_at(), get_name(), EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::XYData::get_yatx(), EMAN::EMData::get_ysize(), EMAN::Util::hypot2(), EMAN::EMUtil::is_same_size(), LOGERR, nimg, normimage, nx, ny, EMAN::EMData::set_complex(), EMAN::EMData::set_complex_at(), EMAN::Dict::set_default(), EMAN::EMData::set_value_at(), EMAN::EMData::to_zero(), v, weight, x, and y.

00309 {
00310         if (!image) {
00311                 return;
00312         }
00313 
00314 
00315 
00316         EMData *img=image->do_fft();
00317         if (nimg >= 1 && !EMUtil::is_same_size(img, result)) {
00318                 LOGERR("%sAverager can only process same-size Image",
00319                            get_name().c_str());
00320                 return;
00321         }
00322         
00323         nimg++;
00324 
00325         int nx = img->get_xsize();
00326         int ny = img->get_ysize();
00327         int nz = 1;
00328 //      size_t image_size = (size_t)nx * ny * nz;
00329 
00330         XYData *weight=(XYData *)image->get_attr("avg_weight");
00331         
00332         if (nimg == 1) {
00333                 result = new EMData(nx,ny,nz);
00334                 result->set_complex(true);
00335                 result->to_zero();
00336 
00337                 normimage = params.set_default("normimage", (EMData*)0);
00338                 if (normimage==0) { normimage=new EMData(nx/2,ny,nz); freenorm=1; }
00339                 normimage->to_zero();
00340         }
00341 
00342         // We're using routines that handle complex image wraparound for us, so we iterate over the half-plane
00343         for (int y=-ny/2; y<ny/2; y++) {
00344                 for (int x=0; x<nx/2; x++) {
00345                         std::complex<float> v=img->get_complex_at(x,y);
00346                         float r=Util::hypot2(y/(float)ny,x/(float)nx);
00347                         float wt=weight->get_yatx(r);
00348                         result->set_complex_at(x,y,result->get_complex_at(x,y)+v*wt);
00349                         normimage->set_value_at(x,y+ny/2,normimage->get_value_at(x,y+ny/2)+wt);
00350                 }
00351         }
00352 
00353         delete img;
00354 }

EMData * FourierWeightAverager::finish  )  [virtual]
 

Finish up the averaging and return the result.

Returns:
The averaged image.

Implements EMAN::Averager.

Definition at line 356 of file averager.cpp.

References EMAN::EMData::do_ift(), EMAN::EMData::get_complex_at(), EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), nimg, norm(), normimage, nx, ny, EMAN::EMData::set_attr(), EMAN::EMData::set_complex_at(), EMAN::EMData::update(), x, and y.

00357 {
00358         EMData *ret = (EMData *)0;
00359         
00360         if (result && nimg >= 1) {
00361         // We're using routines that handle complex image wraparound for us, so we iterate over the half-plane
00362                 int nx = result->get_xsize();
00363                 int ny = result->get_ysize();
00364                 
00365                 for (int y=-ny/2; y<ny/2; y++) {
00366                         for (int x=0; x<nx/2; x++) {
00367                                 float norm=normimage->get_value_at(x,y+ny/2);
00368                                 if (norm<=0) result->set_complex_at(x,y,0.0f);
00369                                 else result->set_complex_at(x,y,result->get_complex_at(x,y)/norm);
00370                         }
00371                 }
00372 
00373                 result->update();
00374 //              result->mult(1.0f/(float)result->get_attr("sigma"));
00375 //              result->write_image("tmp.hdf",0);
00376 //              printf("%g %g %g\n",(float)result->get_attr("sigma"),(float)result->get_attr("minimum"),(float)result->get_attr("maximum"));
00377                 ret=result->do_ift();
00378                 delete result;
00379                 result=(EMData*) 0;
00380         }
00381         ret->set_attr("ptcl_repr",nimg);
00382 
00383         if (freenorm) { delete normimage; normimage=(EMData*)0; }
00384         nimg=0;
00385 
00386         return ret;
00387 }

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

Implements EMAN::Averager.

Definition at line 231 of file averager.h.

00232                 {
00233                         return "Weighted mean of images in Fourier space. Each image must have weighting curve in its header, an XYData object called 'avg_weight'.";
00234                 }

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

Referenced by add_image().

00227                 {
00228                         return NAME;
00229                 }

TypeDict EMAN::FourierWeightAverager::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 241 of file averager.h.

References EMAN::TypeDict::put().

00242                 {
00243                         TypeDict d;
00244 //                      d.put("weight", EMObject::XYDATA, "Radial weight. X: 0 - 0.5*sqrt(2). Y contains weights.");
00245                         d.put("normimage", EMObject::EMDATA, "After finish() will contain the sum of the weights in each Fourier location. Size must be ((nx+1)/2,y)");
00246                         return d;
00247                 }

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

Definition at line 236 of file averager.h.

00237                 {
00238                         return new FourierWeightAverager();
00239                 }


Member Data Documentation

int EMAN::FourierWeightAverager::freenorm [private]
 

Definition at line 253 of file averager.h.

Referenced by add_image().

const string FourierWeightAverager::NAME = "weightedfourier" [static]
 

Definition at line 52 of file averager.cpp.

int EMAN::FourierWeightAverager::nimg [private]
 

Definition at line 254 of file averager.h.

Referenced by add_image(), and finish().

EMData* EMAN::FourierWeightAverager::normimage [private]
 

Definition at line 252 of file averager.h.

Referenced by add_image(), and finish().


The documentation for this class was generated from the following files:
Generated on Tue Jun 11 13:41:53 2013 for EMAN2 by  doxygen 1.3.9.1