#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 | |
| Averager * | NEW () |
Static Public Attributes | |
| const string | NAME = "mean" |
Private Attributes | |
| EMData * | sigma_image |
| int * | nimg_n0 |
| int | ignore0 |
| int | nimg |
It optionally makes a sigma image.
| sigma | sigma value | |
| ignore0 | if set, ignore zero value pixels |
Definition at line 170 of file averager.h.
|
|
Definition at line 186 of file averager.cpp. 00187 : sigma_image(0), nimg_n0(0), ignore0(0), nimg(0) 00188 { 00189 00190 }
|
|
|
To add an image to the Averager. This image will be averaged in this function.
Implements EMAN::Averager. Definition at line 192 of file averager.cpp. References EMAN::EMData::get_data(), get_name(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), ignore0, EMAN::EMUtil::is_same_size(), LOGERR, nimg, nimg_n0, nx, ny, 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 }
|
|
|
Finish up the averaging and return the result.
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(), nimg, nimg_n0, 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 }
|
|
|
Implements EMAN::Averager. Definition at line 183 of file averager.h. 00184 {
00185 return "Simple mean average of images";
00186 }
|
|
|
Get the Averager's name. Each Averager is identified by a unique name.
Implements EMAN::Averager. Definition at line 178 of file averager.h. Referenced by add_image(). 00179 {
00180 return NAME;
00181 }
|
|
|
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::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 }
|
|
|
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.
Reimplemented from EMAN::Averager. Definition at line 201 of file averager.h. 00201 { }
|
|
|
Definition at line 188 of file averager.h. 00189 {
00190 return new ImageAverager();
00191 }
|
|
|
Definition at line 208 of file averager.h. Referenced by add_image(). |
|
|
Definition at line 45 of file averager.cpp. |
|
|
Definition at line 209 of file averager.h. Referenced by add_image(), and finish(). |
|
|
Definition at line 207 of file averager.h. Referenced by add_image(), and finish(). |
|
|
Definition at line 206 of file averager.h. Referenced by add_image(), and finish(). |
1.3.9.1