#include <averager.h>
Inheritance diagram for EMAN::FourierWeightAverager:
Public Member Functions | |
FourierWeightAverager () | |
void | add_image (EMData *image) |
To add an image to the Averager. | |
EMData * | finish () |
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 | |
static Averager * | NEW () |
Static Public Attributes | |
static const string | NAME = "weightedfourier" |
Private Attributes | |
EMData * | normimage |
int | freenorm |
int | nimg |
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.
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.
FourierWeightAverager::FourierWeightAverager | ( | ) |
void FourierWeightAverager::add_image | ( | EMData * | image | ) | [virtual] |
To add an image to the Averager.
This image will be averaged in this function.
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::Util::hypot2(), EMAN::EMUtil::is_same_size(), LOGERR, nimg, normimage, nx, ny, EMAN::Averager::params, EMAN::Averager::result, 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.
Implements EMAN::Averager.
Definition at line 356 of file averager.cpp.
References EMAN::EMData::do_ift(), freenorm, EMAN::EMData::get_complex_at(), EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), nimg, norm(), normimage, nx, ny, EMAN::Averager::result, 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.
Implements EMAN::Averager.
Definition at line 226 of file averager.h.
References NAME.
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.
Reimplemented from EMAN::Averager.
Definition at line 241 of file averager.h.
References EMAN::EMObject::EMDATA, and 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 }
static Averager* EMAN::FourierWeightAverager::NEW | ( | ) | [inline, static] |
Definition at line 236 of file averager.h.
References FourierWeightAverager().
00237 { 00238 return new FourierWeightAverager(); 00239 }
int EMAN::FourierWeightAverager::freenorm [private] |
const string FourierWeightAverager::NAME = "weightedfourier" [static] |
int EMAN::FourierWeightAverager::nimg [private] |
EMData* EMAN::FourierWeightAverager::normimage [private] |