#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 85 of file averager.cpp. 00086 : sigma_image(0), nimg_n0(0), ignore0(0), nimg(0) 00087 { 00088 00089 }
|
|
To add an image to the Averager. This image will be averaged in this function.
Implements EMAN::Averager. Definition at line 91 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. 00092 { 00093 if (!image) { 00094 return; 00095 } 00096 00097 if (nimg >= 1 && !EMUtil::is_same_size(image, result)) { 00098 LOGERR("%sAverager can only process same-size Image", 00099 get_name().c_str()); 00100 return; 00101 } 00102 00103 nimg++; 00104 00105 int nx = image->get_xsize(); 00106 int ny = image->get_ysize(); 00107 int nz = image->get_zsize(); 00108 size_t image_size = nx * ny * nz; 00109 00110 if (nimg == 1) { 00111 result = new EMData(); 00112 result->set_size(nx, ny, nz); 00113 sigma_image = params.set_default("sigma", (EMData*)0); 00114 ignore0 = params["ignore0"]; 00115 00116 nimg_n0 = new int[image_size]; 00117 for (size_t i = 0; i < image_size; i++) { 00118 nimg_n0[i] = 0; 00119 } 00120 } 00121 00122 float *result_data = result->get_data(); 00123 float *sigma_image_data = 0; 00124 if (sigma_image) { 00125 sigma_image->set_size(nx, ny, nz); 00126 sigma_image_data = sigma_image->get_data(); 00127 } 00128 00129 float * image_data = image->get_data(); 00130 00131 if (!ignore0) { 00132 for (size_t j = 0; j < image_size; j++) { 00133 float f = image_data[j]; 00134 result_data[j] += f; 00135 if (sigma_image_data) { 00136 sigma_image_data[j] += f * f; 00137 } 00138 } 00139 } 00140 else { 00141 for (size_t j = 0; j < image_size; j++) { 00142 float f = image_data[j]; 00143 if (f) { 00144 result_data[j] += f; 00145 if (sigma_image_data) { 00146 sigma_image_data[j] += f * f; 00147 } 00148 nimg_n0[j]++; 00149 } 00150 } 00151 } 00152 }
|
|
Finish up the averaging and return the result.
Implements EMAN::Averager. Definition at line 154 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(). 00155 { 00156 if (result && nimg > 1) { 00157 size_t image_size = result->get_xsize() * result->get_ysize() * result->get_zsize(); 00158 float * result_data = result->get_data(); 00159 00160 if (!ignore0) { 00161 for (size_t j = 0; j < image_size; j++) { 00162 result_data[j] /= nimg; 00163 } 00164 00165 if (sigma_image) { 00166 float * sigma_image_data = sigma_image->get_data(); 00167 00168 for (size_t j = 0; j < image_size; j++) { 00169 float f1 = sigma_image_data[j] / nimg; 00170 float f2 = result_data[j]; 00171 sigma_image_data[j] = sqrt(f1 - f2 * f2); 00172 } 00173 00174 sigma_image->update(); 00175 } 00176 } 00177 else { 00178 for (size_t j = 0; j < image_size; j++) { 00179 result_data[j] /= nimg_n0[j]; 00180 } 00181 if (sigma_image) { 00182 float * sigma_image_data = sigma_image->get_data(); 00183 00184 for (size_t j = 0; j < image_size; j++) { 00185 float f1 = sigma_image_data[j] / nimg_n0[j]; 00186 float f2 = result_data[j]; 00187 sigma_image_data[j] = sqrt(f1 - f2 * f2); 00188 } 00189 00190 sigma_image->update(); 00191 } 00192 } 00193 00194 result->update(); 00195 00196 } 00197 result->set_attr("ptcl_repr",nimg); 00198 00199 if( nimg_n0 ) 00200 { 00201 delete [] nimg_n0; 00202 nimg_n0 = 0; 00203 } 00204 00205 return result; 00206 }
|
|
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(). |