#include <averager.h>


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 () |
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.
| ImageAverager::ImageAverager | ( | ) |
Definition at line 73 of file averager.cpp.
Referenced by NEW().
00074 : sigma_image(0), nimg_n0(0), ignore0(0), nimg(0) 00075 { 00076 00077 }
| 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 79 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::Averager::params, EMAN::Averager::result, EMAN::Dict::set_default(), EMAN::EMData::set_size(), and sigma_image.
00080 { 00081 if (!image) { 00082 return; 00083 } 00084 00085 if (nimg >= 1 && !EMUtil::is_same_size(image, result)) { 00086 LOGERR("%sAverager can only process same-size Image", 00087 get_name().c_str()); 00088 return; 00089 } 00090 00091 nimg++; 00092 00093 int nx = image->get_xsize(); 00094 int ny = image->get_ysize(); 00095 int nz = image->get_zsize(); 00096 size_t image_size = nx * ny * nz; 00097 00098 if (nimg == 1) { 00099 result = new EMData(); 00100 result->set_size(nx, ny, nz); 00101 sigma_image = params.set_default("sigma", (EMData*)0); 00102 ignore0 = params["ignore0"]; 00103 00104 nimg_n0 = new int[image_size]; 00105 for (size_t i = 0; i < image_size; i++) { 00106 nimg_n0[i] = 0; 00107 } 00108 } 00109 00110 float *result_data = result->get_data(); 00111 float *sigma_image_data = 0; 00112 if (sigma_image) { 00113 sigma_image->set_size(nx, ny, nz); 00114 sigma_image_data = sigma_image->get_data(); 00115 } 00116 00117 float * image_data = image->get_data(); 00118 00119 if (!ignore0) { 00120 for (size_t j = 0; j < image_size; j++) { 00121 float f = image_data[j]; 00122 result_data[j] += f; 00123 if (sigma_image_data) { 00124 sigma_image_data[j] += f * f; 00125 } 00126 } 00127 } 00128 else { 00129 for (size_t j = 0; j < image_size; j++) { 00130 float f = image_data[j]; 00131 if (f) { 00132 result_data[j] += f; 00133 if (sigma_image_data) { 00134 sigma_image_data[j] += f * f; 00135 } 00136 nimg_n0[j]++; 00137 } 00138 } 00139 } 00140 }
| EMData * ImageAverager::finish | ( | ) | [virtual] |
Finish up the averaging and return the result.
Implements EMAN::Averager.
Definition at line 142 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, sigma_image, sqrt(), and EMAN::EMData::update().
00143 { 00144 if (result && nimg > 1) { 00145 size_t image_size = result->get_xsize() * result->get_ysize() * result->get_zsize(); 00146 float * result_data = result->get_data(); 00147 00148 if (!ignore0) { 00149 for (size_t j = 0; j < image_size; j++) { 00150 result_data[j] /= nimg; 00151 } 00152 00153 if (sigma_image) { 00154 float * sigma_image_data = sigma_image->get_data(); 00155 00156 for (size_t j = 0; j < image_size; j++) { 00157 float f1 = sigma_image_data[j] / nimg; 00158 float f2 = result_data[j]; 00159 sigma_image_data[j] = sqrt(f1 - f2 * f2); 00160 } 00161 00162 sigma_image->update(); 00163 } 00164 } 00165 else { 00166 for (size_t j = 0; j < image_size; j++) { 00167 result_data[j] /= nimg_n0[j]; 00168 } 00169 if (sigma_image) { 00170 float * sigma_image_data = sigma_image->get_data(); 00171 00172 for (size_t j = 0; j < image_size; j++) { 00173 float f1 = sigma_image_data[j] / nimg_n0[j]; 00174 float f2 = result_data[j]; 00175 sigma_image_data[j] = sqrt(f1 - f2 * f2); 00176 } 00177 00178 sigma_image->update(); 00179 } 00180 } 00181 00182 result->update(); 00183 } 00184 00185 if( nimg_n0 ) 00186 { 00187 delete [] nimg_n0; 00188 nimg_n0 = 0; 00189 } 00190 00191 return result; 00192 }
| 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.
Referenced by add_image().
| string EMAN::ImageAverager::get_desc | ( | ) | const [inline, virtual] |
| static Averager* EMAN::ImageAverager::NEW | ( | ) | [inline, static] |
Definition at line 188 of file averager.h.
References ImageAverager().
00189 { 00190 return new ImageAverager(); 00191 }
| 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("ignore0", EMObject::INT, "if set, ignore zero value pixels"); 00198 return d; 00199 }
| virtual void EMAN::ImageAverager::mult | ( | const float & | s | ) | [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 201 of file averager.h.
EMData* EMAN::ImageAverager::sigma_image [private] |
int* EMAN::ImageAverager::nimg_n0 [private] |
int EMAN::ImageAverager::ignore0 [private] |
int EMAN::ImageAverager::nimg [private] |
1.5.6