#include <processor.h>
Inheritance diagram for EMAN::Processor:
Public Types | |
enum | fourier_filter_types { TOP_HAT_LOW_PASS, TOP_HAT_HIGH_PASS, TOP_HAT_BAND_PASS, TOP_HOMOMORPHIC, GAUSS_LOW_PASS, GAUSS_HIGH_PASS, GAUSS_BAND_PASS, GAUSS_INVERSE, GAUSS_HOMOMORPHIC, BUTTERWORTH_LOW_PASS, BUTTERWORTH_HIGH_PASS, BUTTERWORTH_HOMOMORPHIC, KAISER_I0, KAISER_SINH, KAISER_I0_INVERSE, KAISER_SINH_INVERSE, SHIFT, TANH_LOW_PASS, TANH_HIGH_PASS, TANH_HOMOMORPHIC, TANH_BAND_PASS, RADIAL_TABLE, CTF_ } |
Fourier filter Processor type enum. More... | |
Public Member Functions | |
virtual | ~Processor () |
virtual void | process_inplace (EMData *image)=0 |
To process an image in-place. | |
virtual EMData * | process (const EMData *const image) |
To proccess an image out-of-place. | |
virtual void | process_list_inplace (vector< EMData * > &images) |
To process multiple images using the same algorithm. | |
virtual string | get_name () const =0 |
Get the processor's name. | |
virtual Dict | get_params () const |
Get the processor parameters in a key/value dictionary. | |
virtual void | set_params (const Dict &new_params) |
Set the processor parameters using a key/value dictionary. | |
virtual TypeDict | get_param_types () const |
Get processor parameter information in a dictionary. | |
virtual string | get_desc () const =0 |
Get the descrition of this specific processor. | |
Static Public Member Functions | |
string | get_group_desc () |
Get the description of this group of processors. | |
void | EMFourierFilterInPlace (EMData *fimage, Dict params) |
Compute a Fourier-filter processed image in place. | |
EMData * | EMFourierFilter (EMData *fimage, Dict params) |
Compute a Fourier-processor processed image without altering the original image. | |
Protected Attributes | |
Dict | params |
Static Private Member Functions | |
EMData * | EMFourierFilterFunc (EMData *fimage, Dict params, bool doInPlace=true) |
Compute a Fourier-filter processed image. |
vector<string> all_processors = Factory<Processor>::get_list();
EMData *img = ...; img->process_inplace("PROCESSORNAME", Dict("sigma", 12));
string get_name() const { return "processorname"; } static Processor *NEW() { return XYZProcessor(); }
static string get_group_desc();
string get_desc() const;
Dict get_params() const; void set_params(const Dict & new_params); TypeDict get_param_types() const;
Definition at line 93 of file processor.h.
|
Fourier filter Processor type enum. New Fourier filter processors are computed in a single function, EMFourierFilterFunc, that uses a large switch statement to apply the correct filter processor. This enum specifies the filter processor to be applied.
Definition at line 186 of file processor.h. 00186 { 00187 TOP_HAT_LOW_PASS, 00188 TOP_HAT_HIGH_PASS, 00189 TOP_HAT_BAND_PASS, 00190 TOP_HOMOMORPHIC, 00191 GAUSS_LOW_PASS, 00192 GAUSS_HIGH_PASS, 00193 GAUSS_BAND_PASS, 00194 GAUSS_INVERSE, 00195 GAUSS_HOMOMORPHIC, 00196 BUTTERWORTH_LOW_PASS, 00197 BUTTERWORTH_HIGH_PASS, 00198 BUTTERWORTH_HOMOMORPHIC, 00199 KAISER_I0, 00200 KAISER_SINH, 00201 KAISER_I0_INVERSE, 00202 KAISER_SINH_INVERSE, 00203 SHIFT, 00204 TANH_LOW_PASS, 00205 TANH_HIGH_PASS, 00206 TANH_HOMOMORPHIC, 00207 TANH_BAND_PASS, 00208 RADIAL_TABLE, 00209 CTF_, 00210 };
|
|
Definition at line 96 of file processor.h. 00097 { 00098 }
|
|
Compute a Fourier-processor processed image without altering the original image.
Definition at line 268 of file processor.h. 00268 { 00269 bool doInPlace = false; 00270 return EMFourierFilterFunc(fimage, params, doInPlace); 00271 }
|
|
Compute a Fourier-filter processed image. This function is called by either of the convience functions EMFourierFilter or EMFourierFilterInPlace.
Definition at line 58 of file fourierfilter.cpp. References BUTTERWORTH_HIGH_PASS, BUTTERWORTH_HOMOMORPHIC, BUTTERWORTH_LOW_PASS, EMAN::EMData::cmplx(), EMAN::EMData::copy(), CTF_, EMAN::EMData::depad(), EMAN::EMData::do_fft_inplace(), EMAN::EMData::do_ift_inplace(), GAUSS_BAND_PASS, GAUSS_HIGH_PASS, GAUSS_HOMOMORPHIC, GAUSS_INVERSE, GAUSS_LOW_PASS, EMAN::EMData::get_data(), EMAN::EMData::get_ndim(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Util::KaiserBessel::i0win(), iimag(), EMAN::EMData::is_complex(), EMAN::EMData::is_fftodd(), KAISER_I0, KAISER_I0_INVERSE, KAISER_SINH, KAISER_SINH_INVERSE, log10(), LOGERR, max, EMAN::EMData::norm_pad(), nx, ny, pihalf, RADIAL_TABLE, EMAN::EMData::set_array_offsets(), SHIFT, sign, EMAN::Util::KaiserBessel::sinhwin(), EMAN::Dict::size(), sqrt(), TANH_BAND_PASS, TANH_HIGH_PASS, TANH_HOMOMORPHIC, TANH_LOW_PASS, tf(), TOP_HAT_BAND_PASS, TOP_HAT_HIGH_PASS, TOP_HAT_LOW_PASS, TOP_HOMOMORPHIC, twopi, EMAN::EMData::update(), and v. 00059 { 00060 int nx, ny, nz, nyp2, nzp2, ix, iy, iz, jx, jy, jz; 00061 float dx, dy, dz, omega=0, omegaL=0, omegaH=0; 00062 float center=0, gamma=0, argx, argy, argz; 00063 float aa, eps, ord=0, cnst=0, aL, aH, cnstL=0, cnstH=0; 00064 bool complex_input; 00065 vector<float> table; 00066 int undoctf=0; 00067 float voltage=100.0f, ak=0.0f, cs=2.0f, ps=1.0f, b_factor=0.0f, wgh=0.1f, sign=-1.0f; 00068 if (!fimage) return NULL; 00069 const int ndim = fimage->get_ndim(); 00070 // Set amount of Fourier padding 00071 // dopad should be a bool, but EMObject Dict's can't store bools. 00072 int dopad = params["dopad"]; 00073 int npad; 00074 if (0 == dopad) { 00075 // no padding 00076 npad = 1; 00077 } else if (1 == dopad) { 00078 // 2x padding (hard-wired) 00079 npad = 2; 00080 } else if (2 == dopad) { 00081 npad = 4; 00082 } else { 00083 // invalid entry 00084 LOGERR("The dopad parameter must be 0 (false) or 1 (true)"); 00085 return NULL; // FIXME: replace w/ exception throw 00086 } 00087 00088 // If the input image is already a Fourier image, then we want to 00089 // have this routine return a Fourier image 00090 complex_input = fimage->is_complex(); 00091 if ( complex_input && 1 == dopad ) { 00092 // Cannot pad Fourier input image 00093 LOGERR("Cannot pad Fourier input image"); 00094 return NULL; // FIXME: replace w/ exception throw 00095 } 00096 00097 Util::KaiserBessel* kbptr = 0; 00098 00099 00100 nx = fimage->get_xsize(); 00101 ny = fimage->get_ysize(); 00102 nz = fimage->get_zsize(); 00103 // We manifestly assume no zero-padding here, just the 00104 // necessary extension along x for the fft 00105 if (complex_input) nx = (nx - 2 + fimage->is_fftodd()); 00106 00107 const int nxp = npad*nx; 00108 const int nyp = (ny > 1) ? npad*ny : 1; 00109 const int nzp = (nz > 1) ? npad*nz : 1; 00110 00111 int lsd2 = (nxp + 2 - nxp%2) / 2; // Extended x-dimension of the complex image 00112 int lsd3 = lsd2 - 1; 00113 00114 // Perform padding (if necessary) and fft, if the image is not already an fft image 00115 EMData* fp = NULL; // workspace image 00116 if (complex_input) { 00117 if (doInPlace) { 00118 // it's okay to change the original image 00119 fp = fimage; 00120 } else { 00121 // fimage must remain pristine 00122 fp = fimage->copy(); 00123 } 00124 } else { 00125 if (doInPlace) { 00126 if (npad>1) { 00127 LOGERR("Cannot pad with inplace filter"); 00128 return NULL; // FIXME, exception 00129 } 00130 fp=fimage; 00131 fp->do_fft_inplace(); 00132 } else { 00133 fp = fimage->norm_pad( false, npad, 1); 00134 fp->do_fft_inplace(); 00135 } 00136 } 00137 fp->set_array_offsets(1,1,1); 00138 00139 // And the filter type is: 00140 int filter_type = params["filter_type"]; 00141 00142 nyp2 = nyp/2; nzp2 = nzp/2; 00143 dx = 1.0f/float(nxp); 00144 #ifdef _WIN32 00145 dy = 1.0f/_MAX(float(nyp),1.0f); 00146 dz = 1.0f/_MAX(float(nzp),1.0f); 00147 #else 00148 dy = 1.0f/std::max(float(nyp),1.0f); 00149 dz = 1.0f/std::max(float(nzp),1.0f); 00150 #endif //_WIN32 00151 float dx2 = dx*dx, dy2 = dy*dy, dz2 = dz*dz; 00152 00153 vector<float>::size_type tsize; 00154 float sz[3]; 00155 float szmax; 00156 vector<float>::size_type maxsize; 00157 float xshift=0.0, yshift=0.0, zshift=0.0; 00158 00159 // For the given type of filter set up any necessary parameters for the 00160 // filter calculation. FIXME: Need parameter bounds checking! 00161 switch (filter_type) { 00162 case TOP_HAT_LOW_PASS: 00163 case TOP_HAT_HIGH_PASS: 00164 omega = params["cutoff_abs"]; 00165 omega = 1.0f/omega/omega; 00166 break; 00167 case TOP_HAT_BAND_PASS: 00168 omegaL = params["low_cutoff_frequency"]; 00169 omegaH = params["high_cutoff_frequency"]; 00170 omegaL = 1.0f/omegaL/omegaL; 00171 omegaH = 1.0f/omegaH/omegaH; 00172 break; 00173 case TOP_HOMOMORPHIC: 00174 omegaL = params["low_cutoff_frequency"]; 00175 omegaH = params["high_cutoff_frequency"]; 00176 gamma = params["value_at_zero_frequency"]; 00177 omegaL = 1.0f/omegaL/omegaL; 00178 omegaH = 1.0f/omegaH/omegaH; 00179 break; 00180 case GAUSS_LOW_PASS: 00181 case GAUSS_HIGH_PASS: 00182 case GAUSS_INVERSE: 00183 omega = params["cutoff_abs"]; 00184 omega = 0.5f/omega/omega; 00185 break; 00186 case GAUSS_BAND_PASS: 00187 omega = params["cutoff_abs"]; 00188 center = params["center"]; 00189 omega = 0.5f/omega/omega; 00190 break; 00191 case GAUSS_HOMOMORPHIC: 00192 omega = params["cutoff_abs"]; 00193 gamma = params["value_at_zero_frequency"]; 00194 omega = 0.5f/omega/omega; 00195 gamma = 1.0f-gamma; 00196 break; 00197 case BUTTERWORTH_LOW_PASS: 00198 case BUTTERWORTH_HIGH_PASS: 00199 omegaL = params["low_cutoff_frequency"]; 00200 omegaH = params["high_cutoff_frequency"]; 00201 eps = 0.882f; 00202 aa = 10.624f; 00203 ord = 2.0f*log10(eps/sqrt(aa*aa-1.0f))/log10(omegaL/omegaH); 00204 omegaL = omegaL/pow(eps,2.0f/ord); 00205 break; 00206 case BUTTERWORTH_HOMOMORPHIC: 00207 omegaL = params["low_cutoff_frequency"]; 00208 omegaH = params["high_cutoff_frequency"]; 00209 gamma = params["value_at_zero_frequency"]; 00210 eps = 0.882f; 00211 aa = 10.624f; 00212 ord = 2.0f*log10(eps/sqrt(pow(aa,2)-1.0f))/log10(omegaL/omegaH); 00213 omegaL = omegaL/pow(eps,2.0f/ord); 00214 gamma = 1.0f-gamma; 00215 break; 00216 case SHIFT: 00217 xshift = params["x_shift"]; 00218 yshift = params["y_shift"]; 00219 zshift = params["z_shift"]; 00220 //origin_type = params["origin_type"]; 00221 break; 00222 case TANH_LOW_PASS: 00223 case TANH_HIGH_PASS: 00224 omega = params["cutoff_abs"]; 00225 aa = params["fall_off"]; 00226 cnst = float(pihalf/aa/omega); 00227 break; 00228 case TANH_HOMOMORPHIC: 00229 omega = params["cutoff_abs"]; 00230 aa = params["fall_off"]; 00231 gamma = params["value_at_zero_frequency"]; 00232 cnst = float(pihalf/aa/omega); 00233 gamma=1.0f-gamma; 00234 break; 00235 case TANH_BAND_PASS: 00236 omegaL = params["low_cutoff_frequency"]; 00237 aL = params["Low_fall_off"]; 00238 omegaH = params["high_cutoff_frequency"]; 00239 aH = params["high_fall_off"]; 00240 cnstL = float(pihalf/aL/(omegaH-omegaL)); 00241 cnstH = float(pihalf/aH/(omegaH-omegaL)); 00242 break; 00243 case CTF_: 00244 dz = params["defocus"]; 00245 cs = params["Cs"]; 00246 voltage = params["voltage"]; 00247 ps = params["Pixel_size"]; 00248 b_factor = params["B_factor"]; 00249 wgh = params["amp_contrast"]; 00250 sign = params["sign"]; 00251 undoctf = params["undo"]; 00252 ix = params["binary"]; 00253 if(ix == 1) {undoctf = 2; b_factor=0.0;} //ignore B-factor for the binary CTF 00254 break; 00255 case KAISER_I0: 00256 case KAISER_SINH: 00257 case KAISER_I0_INVERSE: 00258 case KAISER_SINH_INVERSE: 00259 { 00260 float alpha = params["alpha"]; 00261 int K = params["K"]; 00262 float r = params["r"]; 00263 float v = params["v"]; 00264 int N = params["N"]; 00265 kbptr = new Util::KaiserBessel(alpha, K, r, v, N); 00266 break; 00267 }//without this bracket, compiler on water will complain about crosses initialization 00268 case RADIAL_TABLE: 00269 table = params["table"]; 00270 tsize = table.size(); 00271 sz[0] = static_cast<float>(lsd2); 00272 sz[1] = static_cast<float>(nyp2); 00273 sz[2] = static_cast<float>(nzp2); 00274 szmax = *max_element(&sz[0],&sz[3]); 00275 // for 2d, sqrt(2) = 1.414, relax a little bit to 1.6 00276 // for 3d, sqrt(3) = 1.732, relax a little bit to 1.9 00277 if (nzp > 1) {maxsize = vector<float>::size_type(1.9*szmax);} else {maxsize = vector<float>::size_type(1.6*szmax);} 00278 for (vector<float>::size_type i = tsize+1; i < maxsize; i++) table.push_back(0.f); 00279 break; 00280 default: 00281 LOGERR("Unknown Fourier Filter type"); 00282 return NULL; // FIXME: replace w/ exception throw 00283 } 00284 // Perform actual calculation 00285 // Gaussian bandpass is the only one with center for frequencies 00286 if(filter_type == GAUSS_BAND_PASS) { 00287 for ( iz = 1; iz <= nzp; iz++) { 00288 jz=iz-1; if(jz>nzp2) jz=jz-nzp; 00289 argz = (float(jz)-center)*(float(jz)-center)*dz2; 00290 for ( iy = 1; iy <= nyp; iy++) { 00291 jy=iy-1; if(jy>nyp2) jy=jy-nyp; 00292 argy = argz + (float(jy)-center)*(float(jy)-center)*dy2; 00293 for ( ix = 1; ix <= lsd2; ix++) { 00294 jx=ix-1; argx = argy + (float(jx)-center)*(float(jx)-center)/float((nxp-1)*(nxp-1)); 00295 // RHS of filter calculation for Gaussian bandpass 00296 fp->cmplx(ix,iy,iz) *= exp(-0.125f*argx*omega); 00297 } 00298 } 00299 } 00300 } else { 00301 switch (filter_type) { 00302 case TOP_HAT_LOW_PASS: 00303 for ( iz = 1; iz <= nzp; iz++) { 00304 jz=iz-1; if (jz>nzp2) jz=jz-nzp; argz = float(jz*jz)*dz2; 00305 for ( iy = 1; iy <= nyp; iy++) { 00306 jy=iy-1; if (jy>nyp2) jy=jy-nyp; argy = argz + float(jy*jy)*dy2; 00307 for ( ix = 1; ix <= lsd2; ix++) { 00308 jx=ix-1; argx = argy + float(jx*jx)*dx2; 00309 if (argx*omega>1.0f) fp->cmplx(ix,iy,iz) = 0; 00310 } 00311 } 00312 } 00313 break; 00314 case TOP_HAT_HIGH_PASS: 00315 for ( iz = 1; iz <= nzp; iz++) { 00316 jz=iz-1; if (jz>nzp2) jz=jz-nzp; argz = float(jz*jz)*dz2; 00317 for ( iy = 1; iy <= nyp; iy++) { 00318 jy=iy-1; if (jy>nyp2) jy=jy-nyp; argy = argz + float(jy*jy)*dy2; 00319 for ( ix = 1; ix <= lsd2; ix++) { 00320 jx=ix-1; argx = argy + float(jx*jx)*dx2; 00321 if (argx*omega<=1.0f) fp->cmplx(ix,iy,iz) = 0; 00322 } 00323 } 00324 } break; 00325 case TOP_HAT_BAND_PASS: 00326 for ( iz = 1; iz <= nzp; iz++) { 00327 jz=iz-1; if (jz>nzp2) jz=jz-nzp; argz = float(jz*jz)*dz2; 00328 for ( iy = 1; iy <= nyp; iy++) { 00329 jy=iy-1; if (jy>nyp2) jy=jy-nyp; argy = argz + float(jy*jy)*dy2; 00330 for ( ix = 1; ix <= lsd2; ix++) { 00331 jx=ix-1; argx = argy + float(jx*jx)*dx2; 00332 if (argx*omegaL<1.0f || argx*omegaH>=1.0f) fp->cmplx(ix,iy,iz) = 0; 00333 } 00334 } 00335 } 00336 break; 00337 case TOP_HOMOMORPHIC: 00338 for ( iz = 1; iz <= nzp; iz++) { 00339 jz=iz-1; if (jz>nzp2) jz=jz-nzp; argz = float(jz*jz)*dz2; 00340 for ( iy = 1; iy <= nyp; iy++) { 00341 jy=iy-1; if (jy>nyp2) jy=jy-nyp; argy = argz + float(jy*jy)*dy2; 00342 for ( ix = 1; ix <= lsd2; ix++) { 00343 jx=ix-1; argx = argy + float(jx*jx)*dx2; 00344 if (argx*omegaH>1.0f) fp->cmplx(ix,iy,iz) = 0.0f; 00345 else if (argx*omegaL<=1.0f) fp->cmplx(ix,iy,iz) *= gamma; 00346 } 00347 } 00348 } 00349 break; 00350 case GAUSS_LOW_PASS : 00351 for ( iz = 1; iz <= nzp; iz++) { 00352 jz=iz-1; if (jz>nzp2) jz=jz-nzp; argz = float(jz*jz)*dz2; 00353 for ( iy = 1; iy <= nyp; iy++) { 00354 jy=iy-1; if (jy>nyp2) jy=jy-nyp; argy = argz + float(jy*jy)*dy2; 00355 for ( ix = 1; ix <= lsd2; ix++) { 00356 jx=ix-1; argx = argy + float(jx*jx)*dx2; 00357 fp->cmplx(ix,iy,iz) *= exp(-argx*omega); 00358 } 00359 } 00360 } 00361 break; 00362 case GAUSS_HIGH_PASS: 00363 for ( iz = 1; iz <= nzp; iz++) { 00364 jz=iz-1; if (jz>nzp2) jz=jz-nzp; argz = float(jz*jz)*dz2; 00365 for ( iy = 1; iy <= nyp; iy++) { 00366 jy=iy-1; if (jy>nyp2) jy=jy-nyp; argy = argz + float(jy*jy)*dy2; 00367 for ( ix = 1; ix <= lsd2; ix++) { 00368 jx=ix-1; argx = argy + float(jx*jx)*dx2; 00369 fp->cmplx(ix,iy,iz) *= 1.0f-exp(-argx*omega); 00370 } 00371 } 00372 } 00373 break; 00374 case GAUSS_HOMOMORPHIC: 00375 for ( iz = 1; iz <= nzp; iz++) { 00376 jz=iz-1; if (jz>nzp2) jz=jz-nzp; argz = float(jz*jz)*dz2; 00377 for ( iy = 1; iy <= nyp; iy++) { 00378 jy=iy-1; if (jy>nyp2) jy=jy-nyp; argy = argz + float(jy*jy)*dy2; 00379 for ( ix = 1; ix <= lsd2; ix++) { 00380 jx=ix-1; argx = argy + float(jx*jx)*dx2; 00381 fp->cmplx(ix,iy,iz) *= 1.0f-gamma*exp(-argx*omega); 00382 } 00383 } 00384 } 00385 break; 00386 case GAUSS_INVERSE : 00387 for ( iz = 1; iz <= nzp; iz++) { 00388 jz=iz-1; if (jz>nzp2) jz=jz-nzp; argz = float(jz*jz)*dz2; 00389 for ( iy = 1; iy <= nyp; iy++) { 00390 jy=iy-1; if (jy>nyp2) jy=jy-nyp; argy = argz + float(jy*jy)*dy2; 00391 for ( ix = 1; ix <= lsd2; ix++) { 00392 jx=ix-1; argx = argy + float(jx*jx)*dx2; 00393 fp->cmplx(ix,iy,iz) *= exp(argx*omega); 00394 } 00395 } 00396 } 00397 break; 00398 case KAISER_I0: // K-B filter 00399 for ( iz = 1; iz <= nzp; iz++) { 00400 jz=iz-1; if (jz>nzp2) jz=jz-nzp; 00401 float nuz = jz*dz; 00402 for ( iy = 1; iy <= nyp; iy++) { 00403 jy=iy-1; if (jy>nyp2) jy=jy-nyp; 00404 float nuy = jy*dy; 00405 for ( ix = 1; ix <= lsd2; ix++) { 00406 jx=ix-1; 00407 float nux = jx*dx; 00408 //if (!kbptr) 00409 // throw 00410 // NullPointerException("kbptr null!"); 00411 switch (ndim) { 00412 case 3: 00413 fp->cmplx(ix,iy,iz) *= kbptr->i0win(nux)*kbptr->i0win(nuy)*kbptr->i0win(nuz); 00414 break; 00415 case 2: 00416 fp->cmplx(ix,iy,iz) *= kbptr->i0win(nux)*kbptr->i0win(nuy); 00417 break; 00418 case 1: 00419 fp->cmplx(ix,iy,iz)*= kbptr->i0win(nux); 00420 break; 00421 } 00422 } 00423 } 00424 } 00425 break; 00426 case KAISER_SINH: // Sinh filter 00427 for ( iz = 1; iz <= nzp; iz++) { 00428 jz=iz-1; if (jz>nzp2) jz=jz-nzp; 00429 for ( iy = 1; iy <= nyp; iy++) { 00430 jy=iy-1; if(jy>nyp2) jy=jy-nyp; 00431 for ( ix = 1; ix <= lsd2; ix++) { 00432 jx=ix-1; 00433 //if (!kbptr) 00434 // throw 00435 // NullPointerException("kbptr null!"); 00436 switch (ndim) { 00437 case 3: 00438 fp->cmplx(ix,iy,iz)*= kbptr->sinhwin((float)jx)*kbptr->sinhwin((float)jy)*kbptr->sinhwin((float)jz); 00439 break; 00440 case 2: 00441 fp->cmplx(ix,iy,iz)*= kbptr->sinhwin((float)jx)*kbptr->sinhwin((float)jy); 00442 break; 00443 case 1: 00444 fp->cmplx(ix,iy,iz)*= kbptr->sinhwin((float)jx); 00445 //float argu = kbptr->sinhwin((float) jx); 00446 //cout << jx<<" "<< nux<<" "<<argu<<endl; 00447 break; 00448 } 00449 } 00450 } 00451 } 00452 break; 00453 case KAISER_I0_INVERSE: // 1./(K-B filter) 00454 for ( iz = 1; iz <= nzp; iz++) { 00455 jz=iz-1; if (jz>nzp2) jz=jz-nzp; 00456 float nuz = jz*dz; 00457 for ( iy = 1; iy <= nyp; iy++) { 00458 jy=iy-1; if(jy>nyp2) jy=jy-nyp; 00459 float nuy = jy*dy; 00460 for ( ix = 1; ix <= lsd2; ix++) { 00461 jx=ix-1; 00462 float nux = jx*dx; 00463 //if (!kbptr) 00464 // throw 00465 // NullPointerException("kbptr null!"); 00466 switch (ndim) { 00467 case 3: 00468 fp->cmplx(ix,iy,iz) /= (kbptr->i0win(nux)*kbptr->i0win(nuy)*kbptr->i0win(nuz)); 00469 break; 00470 case 2: 00471 fp->cmplx(ix,iy,iz) /= (kbptr->i0win(nux)*kbptr->i0win(nuy)); 00472 break; 00473 case 1: 00474 fp->cmplx(ix,iy,iz) /= kbptr->i0win(nux); 00475 break; 00476 } 00477 } 00478 } 00479 } 00480 break; 00481 case KAISER_SINH_INVERSE: // 1./sinh 00482 for ( iz = 1; iz <= nzp; iz++) { 00483 jz=iz-1; if (jz>nzp2) jz=jz-nzp; 00484 for ( iy = 1; iy <= nyp; iy++) { 00485 jy=iy-1; if (jy>nyp2) jy=jy-nyp; 00486 for ( ix = 1; ix <= lsd2; ix++) { 00487 jx=ix-1; 00488 //if (!kbptr) 00489 // throw 00490 // NullPointerException("kbptr null!"); 00491 switch (ndim) { 00492 case 3: 00493 fp->cmplx(ix,iy,iz) /= (kbptr->sinhwin((float)jx)*kbptr->sinhwin((float)jy)*kbptr->sinhwin((float)jz)); 00494 break; 00495 case 2: 00496 fp->cmplx(ix,iy,iz) /= (kbptr->sinhwin((float)jx)*kbptr->sinhwin((float)jy)); 00497 break; 00498 case 1: 00499 fp->cmplx(ix,iy,iz) /= kbptr->sinhwin((float)jx); 00500 //float argu = kbptr->sinhwin((float) jx); 00501 //cout << jx<<" "<< nux<<" "<<argu<<endl; 00502 break; 00503 } 00504 } 00505 } 00506 } 00507 break; 00508 case BUTTERWORTH_LOW_PASS: 00509 for ( iz = 1; iz <= nzp; iz++) { 00510 jz=iz-1; if (jz>nzp2) jz=jz-nzp; argz = float(jz*jz)*dz2; 00511 for ( iy = 1; iy <= nyp; iy++) { 00512 jy=iy-1; if (jy>nyp2) jy=jy-nyp; argy = argz + float(jy*jy)*dy2; 00513 for ( ix = 1; ix <= lsd2; ix++) { 00514 jx=ix-1; argx = argy + float(jx*jx)*dx2; 00515 fp->cmplx(ix,iy,iz) *= sqrt(1.0f/(1.0f+pow(sqrt(argx)/omegaL,ord))); 00516 } 00517 } 00518 } 00519 break; 00520 case BUTTERWORTH_HIGH_PASS: 00521 for ( iz = 1; iz <= nzp; iz++) { 00522 jz=iz-1; if (jz>nzp2) jz=jz-nzp; argz = float(jz*jz)*dz2; 00523 for ( iy = 1; iy <= nyp; iy++) { 00524 jy=iy-1; if (jy>nyp2) jy=jy-nyp; argy = argz + float(jy*jy)*dy2; 00525 for ( ix = 1; ix <= lsd2; ix++) { 00526 jx=ix-1; argx = argy + float(jx*jx)*dx2; 00527 fp->cmplx(ix,iy,iz) *= 1.0f-sqrt(1.0f/(1.0f+pow(sqrt(argx)/omegaL,ord))); 00528 } 00529 } 00530 } 00531 break; 00532 case BUTTERWORTH_HOMOMORPHIC: 00533 for ( iz = 1; iz <= nzp; iz++) { 00534 jz=iz-1; if (jz>nzp2) jz=jz-nzp; argz = float(jz*jz)*dz2; 00535 for ( iy = 1; iy <= nyp; iy++) { 00536 jy=iy-1; if (jy>nyp2) jy=jy-nyp; argy = argz + float(jy*jy)*dy2; 00537 for ( ix = 1; ix <= lsd2; ix++) { 00538 jx=ix-1; argx = argy + float(jx*jx)*dx2; 00539 fp->cmplx(ix,iy,iz) *= 1.0f-gamma*sqrt(1.0f/(1.0f+pow(sqrt(argx)/omegaL,ord))); 00540 } 00541 } 00542 } 00543 break; 00544 case SHIFT: 00545 //if (origin_type) { 00546 for ( iz = 1; iz <= nzp; iz++) { 00547 jz=iz-1; if (jz>nzp2) jz=jz-nzp; 00548 for ( iy = 1; iy <= nyp; iy++) { 00549 jy=iy-1; if (jy>nyp2) jy=jy-nyp; 00550 for ( ix = 1; ix <= lsd2; ix++) { 00551 jx=ix-1; 00552 fp->cmplx(ix,iy,iz) *= exp(-float(twopi)*iimag*(xshift*jx/nx + yshift*jy/ny+ zshift*jz/nz)); 00553 } 00554 } 00555 } 00556 /*} else { 00557 for ( iz = 1; iz <= nzp; iz++) { 00558 jz=iz-1; if (jz>nzp2) jz=jz-nzp; 00559 if (iz>nzp2) { kz=iz-nzp2; } else { kz=iz+nzp2; } 00560 for ( iy = 1; iy <= nyp; iy++) { 00561 jy=iy-1; if (jy>nyp2) jy=jy-nyp; 00562 if (iy>nyp2) { ky=iy-nyp2; } else { ky=iy+nyp2; } 00563 for ( ix = 1; ix <= lsd2; ix++) { 00564 jx=ix-1; 00565 fp->cmplx(ix,ky,kz) *= exp(-float(twopi)*iimag*(xshift*jx/nx + yshift*jy/ny+ zshift*jz/nz)); 00566 } 00567 } 00568 } 00569 }*/ 00570 break; 00571 case TANH_LOW_PASS: 00572 for ( iz = 1; iz <= nzp; iz++) { 00573 jz=iz-1; if (jz>nzp2) jz=jz-nzp; argz = float(jz*jz)*dz2; 00574 for ( iy = 1; iy <= nyp; iy++) { 00575 jy=iy-1; if (jy>nyp2) jy=jy-nyp; argy = argz + float(jy*jy)*dy2; 00576 for ( ix = 1; ix <= lsd2; ix++) { 00577 jx=ix-1; argx = sqrt(argy + float(jx*jx)*dx2); 00578 fp->cmplx(ix,iy,iz) *= 0.5f*(tanh(cnst*(argx+omega))-tanh(cnst*(argx-omega))); 00579 } 00580 } 00581 } 00582 break; 00583 case TANH_HIGH_PASS: 00584 for ( iz = 1; iz <= nzp; iz++) { 00585 jz=iz-1; if (jz>nzp2) jz=jz-nzp; argz = float(jz*jz)*dz2; 00586 for ( iy = 1; iy <= nyp; iy++) { 00587 jy=iy-1; if (jy>nyp2) jy=jy-nyp; argy = argz + float(jy*jy)*dy2; 00588 for ( ix = 1; ix <= lsd2; ix++) { 00589 jx=ix-1; sqrt(argx = argy + float(jx*jx)*dx2); 00590 fp->cmplx(ix,iy,iz) *= 1.0f-0.5f*(tanh(cnst*(argx+omega))-tanh(cnst*(argx-omega))); 00591 } 00592 } 00593 } 00594 break; 00595 case TANH_HOMOMORPHIC: 00596 for ( iz = 1; iz <= nzp; iz++) { 00597 jz=iz-1; if (jz>nzp2) jz=jz-nzp; argz = float(jz*jz)*dz2; 00598 for ( iy = 1; iy <= nyp; iy++) { 00599 jy=iy-1; if (jy>nyp2) jy=jy-nyp; argy = argz + float(jy*jy)*dy2; 00600 for ( ix = 1; ix <= lsd2; ix++) { 00601 jx=ix-1; argx = sqrt(argy + float(jx*jx)*dx2); 00602 fp->cmplx(ix,iy,iz) *= 1.0f-gamma*0.5f*(tanh(cnst*(argx+omega))-tanh(cnst*(argx-omega))); 00603 } 00604 } 00605 } 00606 break; 00607 case TANH_BAND_PASS: 00608 for ( iz = 1; iz <= nzp; iz++) { 00609 jz=iz-1; if (jz>nzp2) jz=jz-nzp; argz = float(jz*jz)*dz2; 00610 for ( iy = 1; iy <= nyp; iy++) { 00611 jy=iy-1; if (jy>nyp2) jy=jy-nyp; argy = argz + float(jy*jy)*dy2; 00612 for ( ix = 1; ix <= lsd2; ix++) { 00613 jx=ix-1; argx = sqrt(argy + float(jx*jx)*dx2); 00614 fp->cmplx(ix,iy,iz) *= 0.5f*(tanh(cnstH*(argx+omegaH))-tanh(cnstH*(argx-omegaH))-tanh(cnstL*(argx+omegaL))+tanh(cnstL*(argx-omegaL))); 00615 } 00616 } 00617 } 00618 break; 00619 case RADIAL_TABLE: 00620 for ( iz = 1; iz <= nzp; iz++) { 00621 jz=iz-1; if (jz>nzp2) jz=jz-nzp; argz = float(jz*jz)*dz2; 00622 for ( iy = 1; iy <= nyp; iy++) { 00623 jy=iy-1; if (jy>nyp2) jy=jy-nyp; argy = argz + float(jy*jy)*dy2; 00624 for ( ix = 1; ix <= lsd2; ix++) { 00625 jx=ix-1; argx = argy + float(jx*jx)*dx2; 00626 float rf = sqrt( argx )*nxp; 00627 int ir = int(rf); 00628 float df = rf - float(ir); 00629 float f = table[ir] + df * (table[ir+1] - table[ir]); // (1-df)*table[ir]+df*table[ir+1]; 00630 fp->cmplx(ix,iy,iz) *= f; 00631 } 00632 } 00633 } 00634 break; 00635 case CTF_: 00636 for ( iz = 1; iz <= nzp; iz++) { 00637 jz=iz-1; if (jz>nzp2) jz=jz-nzp; 00638 for ( iy = 1; iy <= nyp; iy++) { 00639 jy=iy-1; if (jy>nyp2) jy=jy-nyp; 00640 for ( ix = 1; ix <= lsd2; ix++) { 00641 jx=ix-1; 00642 if(ny>1 && nz<=1 ) ak=sqrt(static_cast<float>(jx)/lsd3*static_cast<float>(jx)/lsd3 + 00643 static_cast<float>(jy)/nyp2*static_cast<float>(jy)/nyp2)/ps/2.0f; 00644 else if(ny<=1) ak=sqrt(static_cast<float>(jx)/lsd3*static_cast<float>(jx)/lsd3)/ps/2.0f; 00645 else if(nz>1) ak=sqrt(static_cast<float>(jx)/lsd3*static_cast<float>(jx)/lsd3 + 00646 static_cast<float>(jy)/nyp2*static_cast<float>(jy)/nyp2 + 00647 static_cast<float>(jz)/nzp2*static_cast<float>(jz)/nzp2)/ps/2.0f; 00648 float tf=Util::tf(dz, ak, voltage, cs, wgh, b_factor, sign); 00649 switch (undoctf) { 00650 case 0: 00651 fp->cmplx(ix,iy,iz) *= tf; 00652 break; 00653 case 1: 00654 if( tf>0 && tf < 1e-5 ) tf = 1e-5f; 00655 if( tf<0 && tf > -1e-5 ) tf = -1e-5f; 00656 fp->cmplx(ix,iy,iz) /= tf; 00657 break; 00658 case 2: 00659 if(tf < 0.0f) fp->cmplx(ix,iy,iz) *= -1.0f; 00660 break; 00661 } 00662 } 00663 } 00664 } 00665 break; 00666 } 00667 } 00668 delete kbptr; kbptr = 0; 00669 if (!complex_input) { 00670 fp->do_ift_inplace(); 00671 fp->depad(); 00672 } 00673 00674 // Return a complex (Fourier) filtered image 00675 // Note: fp and fimage are the _same_ object if doInPlace 00676 // is true, so in that case fimage has been filtered. 00677 // We always return an image (pointer), but if the function 00678 // was called with doInPlace == true then the calling function 00679 // will probably ignore the return value. 00680 00681 // ELSE Return a real-space filtered image 00682 // 00683 // On 12/15/2006 Wei Zhang comment: 00684 // If input is reald and doInPlace == true, we might need delete fp after copy its 00685 // data back to fimage, since fp is allocated inside this function and is ignored 00686 // by caller if doInPlace == true. As a reminder, the caller is EMFourierFuncInPlace 00687 // 00688 fp->set_array_offsets(0,0,0); 00689 fp->update(); 00690 if (doInPlace && !complex_input) { 00691 // copy workspace data into the original image 00692 float* orig = fimage->get_data(); 00693 float* work = fp->get_data(); 00694 for (int i = 0; i < nx*ny*nz; i++) orig[i] = work[i]; 00695 fimage->update(); 00696 } 00697 return fp; 00698 EXITFUNC; 00699 }
|
|
Compute a Fourier-filter processed image in place.
Definition at line 237 of file processor.h. 00237 { 00238 bool doInPlace = true; 00239 EMFourierFilterFunc(fimage, params, doInPlace); 00240 }
|
|
|
Get the description of this group of processors. This function is defined in a parent class. It gives a introduction to a group of processors.
Reimplemented in EMAN::ImageProcessor, EMAN::FourierProcessor, EMAN::FourierAnlProcessor, EMAN::LowpassFourierProcessor, EMAN::HighpassFourierProcessor, EMAN::RealPixelProcessor, EMAN::CoordinateProcessor, EMAN::ComplexPixelProcessor, EMAN::BoxStatProcessor, EMAN::NormalizeProcessor, EMAN::TestImageProcessor, and EMAN::NewFourierProcessor. Definition at line 163 of file processor.h. 00164 { 00165 return "EMAN processors are in-place image processors. You may apply a processor to process a single image or process multiple images. Processor class is the base class for all processor. <br> \ 00166 The basic design of EMAN Processors: <br>\ 00167 1) Each Processor class defines an image-processinging algorithm. <br>\ 00168 2) All the Processor classes in EMAN are managed by a Factory pattern. So each Processor class must define: <br> a) a unique name to idenfity itself in the factory. <br>b) a static method to register itself in the factory.<br>\ 00169 3) Each Processor class defines its own parameter set.<br>\ 00170 4) Each Processor class defines functions to return its documentation including parameter information, and processor description. These functions enable EMAN to generate processor manuals dynamically."; 00171 }
|
|
|
|
Get the processor parameters in a key/value dictionary.
Definition at line 133 of file processor.h. 00134 {
00135 return params;
00136 }
|
|
To proccess an image out-of-place. For those processors which can only be processed out-of-place, override this function to give the right behavior.
Reimplemented in EMAN::Wiener2DAutoAreaProcessor, EMAN::KmeansSegmentProcessor, EMAN::Wiener2DFourierProcessor, EMAN::TransformProcessor, EMAN::IntTranslateProcessor, EMAN::ScaleTransformProcessor, EMAN::MaxShrinkProcessor, EMAN::MinShrinkProcessor, EMAN::MeanShrinkProcessor, EMAN::MedianShrinkProcessor, EMAN::FFTResampleProcessor, EMAN::TransposeProcessor, and EMAN::DirectionalSumProcessor. Definition at line 488 of file processor.cpp. References EMAN::EMData::copy(), and process_inplace(). Referenced by EMAN::EMData::process(). 00489 { 00490 EMData * result = image->copy(); 00491 process_inplace(result); 00492 return result; 00493 }
|
|
|
To process multiple images using the same algorithm.
Definition at line 118 of file processor.h. References images, and process_inplace(). 00119 { 00120 for (size_t i = 0; i < images.size(); i++) { 00121 process_inplace(images[i]); 00122 } 00123 }
|
|
Set the processor parameters using a key/value dictionary.
Reimplemented in EMAN::SNREvalProcessor, EMAN::AmpweightFourierProcessor, EMAN::Wiener2DAutoAreaProcessor, EMAN::Wiener2DFourierProcessor, EMAN::LowpassFourierProcessor, EMAN::HighpassFourierProcessor, EMAN::LinearRampProcessor, EMAN::RealPixelProcessor, EMAN::InvertCarefullyProcessor, EMAN::ValuePowProcessor, EMAN::CollapseProcessor, EMAN::LinearXformProcessor, EMAN::ExpProcessor, EMAN::FiniteProcessor, EMAN::RangeThresholdProcessor, EMAN::SigmaProcessor, EMAN::CircularMaskProcessor, EMAN::MaskSharpProcessor, EMAN::MaskEdgeMeanProcessor, EMAN::MaskGaussProcessor, EMAN::MaskGaussNonuniformProcessor, EMAN::AreaProcessor, EMAN::PeakOnlyProcessor, and EMAN::PaintProcessor. Definition at line 141 of file processor.h. 00142 { 00143 params = new_params; 00144 }
|
|
Definition at line 313 of file processor.h. Referenced by EMAN::FlipProcessor::process_inplace(). |