#include <averager.h>
Inheritance diagram for EMAN::ImageAverager:
Public Member Functions | |
ImageAverager () | |
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. | |
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 Averager * | NEW () |
Static Public Attributes | |
static const string | NAME = "mean" |
Private Attributes | |
EMData * | sigma_image |
EMData * | normimage |
int | ignore0 |
int | nimg |
int | freenorm |
It optionally makes a sigma image.
sigma | sigma value | |
ignore0 | if set, ignore zero value pixels |
Definition at line 170 of file averager.h.
ImageAverager::ImageAverager | ( | ) |
Definition at line 183 of file averager.cpp.
Referenced by NEW().
00184 : sigma_image(0), ignore0(0), normimage(0), freenorm(0), nimg(0) 00185 { 00186 00187 }
void ImageAverager::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 189 of file averager.cpp.
References EMAN::EMData::copy_head(), freenorm, EMAN::EMData::get_data(), get_name(), EMAN::EMData::get_value_at(), ignore0, EMAN::EMUtil::is_same_size(), LOGERR, nimg, normimage, nx, ny, EMAN::Averager::params, EMAN::Averager::result, EMAN::Dict::set_default(), EMAN::EMData::set_size(), EMAN::EMData::set_value_at_fast(), sigma_image, and EMAN::EMData::to_zero().
00190 { 00191 if (!image) { 00192 return; 00193 } 00194 00195 if (nimg >= 1 && !EMUtil::is_same_size(image, result)) { 00196 LOGERR("%sAverager can only process same-size Image", 00197 get_name().c_str()); 00198 return; 00199 } 00200 00201 nimg++; 00202 00203 int nx = image->get_xsize(); 00204 int ny = image->get_ysize(); 00205 int nz = image->get_zsize(); 00206 size_t image_size = (size_t)nx * ny * nz; 00207 00208 if (nimg == 1) { 00209 result = image->copy_head(); 00210 result->set_size(nx, ny, nz); 00211 sigma_image = params.set_default("sigma", (EMData*)0); 00212 ignore0 = params["ignore0"]; 00213 00214 normimage = params.set_default("normimage", (EMData*)0); 00215 if (ignore0 && normimage==0) { normimage=new EMData(nx,ny,nz); freenorm=1; } 00216 if (normimage) normimage->to_zero(); 00217 } 00218 00219 float *result_data = result->get_data(); 00220 float *sigma_image_data = 0; 00221 if (sigma_image) { 00222 sigma_image->set_size(nx, ny, nz); 00223 sigma_image_data = sigma_image->get_data(); 00224 } 00225 00226 float * image_data = image->get_data(); 00227 00228 if (!ignore0) { 00229 for (size_t j = 0; j < image_size; ++j) { 00230 float f = image_data[j]; 00231 result_data[j] += f; 00232 if (sigma_image_data) { 00233 sigma_image_data[j] += f * f; 00234 } 00235 } 00236 } 00237 else { 00238 for (size_t j = 0; j < image_size; ++j) { 00239 float f = image_data[j]; 00240 if (f) { 00241 result_data[j] += f; 00242 if (sigma_image_data) { 00243 sigma_image_data[j] += f * f; 00244 } 00245 normimage->set_value_at_fast(j,normimage->get_value_at(j)+1.0); 00246 } 00247 } 00248 } 00249 }
EMData * ImageAverager::finish | ( | ) | [virtual] |
Finish up the averaging and return the result.
Implements EMAN::Averager.
Definition at line 251 of file averager.cpp.
References freenorm, EMAN::EMData::get_data(), EMAN::EMData::get_value_at(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ignore0, nimg, normimage, EMAN::Averager::result, EMAN::EMData::set_attr(), sigma_image, sqrt(), and EMAN::EMData::update().
00252 { 00253 if (result && nimg > 1) { 00254 size_t image_size = (size_t)result->get_xsize() * result->get_ysize() * result->get_zsize(); 00255 float * result_data = result->get_data(); 00256 00257 if (!ignore0) { 00258 for (size_t j = 0; j < image_size; ++j) { 00259 result_data[j] /= nimg; 00260 } 00261 00262 if (sigma_image) { 00263 float * sigma_image_data = sigma_image->get_data(); 00264 00265 for (size_t j = 0; j < image_size; ++j) { 00266 float f1 = sigma_image_data[j] / nimg; 00267 float f2 = result_data[j]; 00268 sigma_image_data[j] = sqrt(f1 - f2 * f2); 00269 } 00270 00271 sigma_image->update(); 00272 } 00273 } 00274 else { 00275 for (size_t j = 0; j < image_size; ++j) { 00276 if (normimage->get_value_at(j)>0) result_data[j] /= normimage->get_value_at(j); 00277 } 00278 if (sigma_image) { 00279 float * sigma_image_data = sigma_image->get_data(); 00280 00281 for (size_t j = 0; j < image_size; ++j) { 00282 float f1 = 0; 00283 if (normimage->get_value_at(j)>0) f1=sigma_image_data[j] / normimage->get_value_at(j); 00284 float f2 = result_data[j]; 00285 sigma_image_data[j] = sqrt(f1 - f2 * f2); 00286 } 00287 00288 sigma_image->update(); 00289 } 00290 } 00291 00292 result->update(); 00293 00294 } 00295 result->set_attr("ptcl_repr",nimg); 00296 00297 if (freenorm) { delete normimage; normimage=(EMData*)0; } 00298 00299 return result; 00300 }
string EMAN::ImageAverager::get_desc | ( | ) | const [inline, virtual] |
string EMAN::ImageAverager::get_name | ( | ) | const [inline, virtual] |
Get the Averager's name.
Each Averager is identified by a unique 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.
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("normimage", EMObject::EMDATA, "In conjunction with ignore0, the number of non zero values for each pixel will be stored in this image."); 00198 d.put("ignore0", EMObject::INT, "if set, ignore zero value pixels"); 00199 return d; 00200 }
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.
s | the scaling factor. |
NullPointerException | if the EMData pointer (result) is NULL |
Reimplemented from EMAN::Averager.
Definition at line 202 of file averager.h.
static Averager* EMAN::ImageAverager::NEW | ( | ) | [inline, static] |
Definition at line 188 of file averager.h.
References ImageAverager().
00189 { 00190 return new ImageAverager(); 00191 }
int EMAN::ImageAverager::freenorm [private] |
int EMAN::ImageAverager::ignore0 [private] |
const string ImageAverager::NAME = "mean" [static] |
int EMAN::ImageAverager::nimg [private] |
EMData * EMAN::ImageAverager::normimage [private] |
EMData* EMAN::ImageAverager::sigma_image [private] |