#include <cmp.h>
Inheritance diagram for EMAN::FRCCmp:
Public Member Functions | |
float | cmp (EMData *image, EMData *with) const |
To compare 'image' with another image passed in through its parameters. | |
string | get_name () const |
Get the Cmp's name. | |
string | get_desc () const |
TypeDict | get_param_types () const |
Get Cmp parameter information in a dictionary. | |
Static Public Member Functions | |
Cmp * | NEW () |
Static Public Attributes | |
const string | NAME = "frc" |
Fourier ring correlation (FRC) is a measure of statistical dependency between two averages, computed by comparison of rings in Fourier space. 1 means prefect agreement. 0 means no correlation.
Definition at line 508 of file cmp.h.
|
To compare 'image' with another image passed in through its parameters. An optional transformation may be used to transform the 2 images.
Implements EMAN::Cmp. Definition at line 1119 of file cmp.cpp. References EMAN::Ctf::apix, EMAN::EMData::calc_fourier_shell_correlation(), EMAN::EMData::calc_radial_dist(), EMAN::Ctf::compute_1d(), EMAN::EMData::copy(), EMAN::EMData::do_fft(), EMAN::EMData::do_fft_inplace(), EMAN::EMObject::f, EMAN::EMData::get_attr(), EMAN::EMData::get_attr_default(), EMAN::EMData::get_data(), EMAN::EMData::get_xsize(), EMAN::EMData::get_ysize(), EMAN::EMData::get_zsize(), EMAN::Util::goodf(), EMAN::EMData::has_attr(), InvalidCallException, EMAN::EMData::is_complex(), norm(), ny, EMAN::EMData::set_attr(), EMAN::Dict::set_default(), EMAN::EMData::update(), EMAN::Cmp::validate_input_args(), and weight. 01120 { 01121 ENTERFUNC; 01122 validate_input_args(image, with); 01123 01124 int snrweight = params.set_default("snrweight", 0); 01125 int ampweight = params.set_default("ampweight", 0); 01126 int sweight = params.set_default("sweight", 1); 01127 int nweight = params.set_default("nweight", 0); 01128 int zeromask = params.set_default("zeromask",0); 01129 float minres = params.set_default("minres",500.0f); 01130 float maxres = params.set_default("maxres",2.0f); 01131 01132 vector < float >fsc; 01133 bool use_cpu = true; 01134 01135 if (use_cpu) { 01136 if (zeromask) { 01137 image=image->copy(); 01138 with=with->copy(); 01139 01140 int sz=image->get_xsize()*image->get_ysize()*image->get_zsize(); 01141 float *d1=image->get_data(); 01142 float *d2=with->get_data(); 01143 01144 for (int i=0; i<sz; i++) { 01145 if (d1[i]==0.0 || d2[i]==0.0) { d1[i]=0.0; d2[i]=0.0; } 01146 } 01147 01148 image->update(); 01149 with->update(); 01150 image->do_fft_inplace(); 01151 with->do_fft_inplace(); 01152 image->set_attr("free_me",1); 01153 with->set_attr("free_me",1); 01154 } 01155 01156 01157 if (!image->is_complex()) { 01158 image=image->do_fft(); 01159 image->set_attr("free_me",1); 01160 } 01161 if (!with->is_complex()) { 01162 with=with->do_fft(); 01163 with->set_attr("free_me",1); 01164 } 01165 01166 fsc = image->calc_fourier_shell_correlation(with,1); 01167 } 01168 01169 int ny = image->get_ysize(); 01170 int ny2=ny/2+1; 01171 01172 // The fast hypot here was supposed to speed things up. Little effect 01173 // if (image->get_zsize()>1) fsc = image->calc_fourier_shell_correlation(with,1); 01174 // else { 01175 // double *sxy = (double *)malloc(ny2*sizeof(double)*4); 01176 // double *sxx = sxy+ny2; 01177 // double *syy = sxy+2*ny2; 01178 // double *norm= sxy+3*ny2; 01179 // 01180 // float *df1=image->get_data(); 01181 // float *df2=with->get_data(); 01182 // int nx2=image->get_xsize(); 01183 // 01184 // for (int y=-ny/2; y<ny/2; y++) { 01185 // for (int x=0; x<nx2/2; x++) { 01186 // if (x==0 && y<0) continue; // skip Friedel pair 01187 // short r=Util::hypot_fast_int(x,y); 01188 // if (r>ny2-1) continue; 01189 // int l=x*2+(y<0?ny+y:y)*nx2; 01190 // sxy[r]+=df1[l]*df2[l]+df1[l+1]*df2[l+1]; 01191 // sxx[r]+=df1[l]*df1[l]; 01192 // syy[r]+=df2[l]*df2[l]; 01193 // norm[r]+=1.0; 01194 // } 01195 // } 01196 // fsc.resize(ny2*3); 01197 // for (int r=0; r<ny2; r++) { 01198 // fsc[r]=r*0.5/ny2; 01199 // fsc[ny2+r]=sxy[r]/(sqrt(sxx[r])*sqrt(syy[r])); 01200 // fsc[ny2*2+r]=norm[r]; 01201 // } 01202 // free(sxy); 01203 // } 01204 01205 vector<float> snr; 01206 if (snrweight) { 01207 Ctf *ctf = NULL; 01208 if (!image->has_attr("ctf")) { 01209 if (!with->has_attr("ctf")) throw InvalidCallException("SNR weight with no CTF parameters"); 01210 ctf=with->get_attr("ctf"); 01211 } 01212 else ctf=image->get_attr("ctf"); 01213 01214 float ds=1.0f/(ctf->apix*ny); 01215 snr=ctf->compute_1d(ny,ds,Ctf::CTF_SNR); 01216 if(ctf) {delete ctf; ctf=0;} 01217 } 01218 01219 vector<float> amp; 01220 if (ampweight) amp=image->calc_radial_dist(ny/2,0,1,0); 01221 01222 // Min/max modifications to weighting 01223 float pmin,pmax; 01224 if (minres>0) pmin=((float)image->get_attr("apix_x")*image->get_ysize())/minres; //cutoff in pixels, assume square 01225 else pmin=0; 01226 if (maxres>0) pmax=((float)image->get_attr("apix_x")*image->get_ysize())/maxres; 01227 else pmax=0; 01228 01229 double sum=0.0, norm=0.0; 01230 01231 for (int i=0; i<ny/2; i++) { 01232 double weight=1.0; 01233 if (sweight) weight*=fsc[(ny2)*2+i]; 01234 if (ampweight) weight*=amp[i]; 01235 if (snrweight) weight*=snr[i]; 01236 // if (snrweight) { 01237 // if (snr[i]>0) weight*=sqrt(snr[i]); 01238 // else weight=0; 01239 // } 01240 //if(snr[i]<0) printf("snr[%d] = %1.5g\n",i,snr[i]); 01241 if (pmin>0) weight*=(tanh(5.0*(i-pmin)/pmin)+1.0)/2.0; 01242 if (pmax>0) weight*=(1.0-tanh(i-pmax))/2.0; 01243 01244 sum+=weight*fsc[ny2+i]; 01245 norm+=weight; 01246 // printf("%d\t%f\t%f\n",i,weight,fsc[ny/2+1+i]); 01247 } 01248 01249 // This performs a weighting that tries to normalize FRC by correcting from the number of particles represented by the average 01250 sum/=norm; 01251 if (nweight && with->get_attr_default("ptcl_repr",0) && sum>=0 && sum<1.0) { 01252 sum=sum/(1.0-sum); // convert to SNR 01253 sum/=(float)with->get_attr_default("ptcl_repr",0); // divide by ptcl represented 01254 sum=sum/(1.0+sum); // convert back to correlation 01255 } 01256 01257 if (image->has_attr("free_me")) delete image; 01258 if (with->has_attr("free_me")) delete with; 01259 01260 EXITFUNC; 01261 01262 01263 if (!Util::goodf(&sum)) sum=-3.0e38; 01264 //.Note the negative! This is because EMAN2 follows the convention that 01265 // smaller return values from comparitors indicate higher similarity - 01266 // this enables comparitors to be used in a generic fashion. 01267 return (float)-sum; 01268 }
|
|
Implements EMAN::Cmp. Definition at line 518 of file cmp.h. 00519 { 00520 return "Computes the mean Fourier Ring Correlation between the image and reference (with optional weighting factors)."; 00521 }
|
|
Get the Cmp's name. Each Cmp is identified by a unique name.
Implements EMAN::Cmp. Definition at line 513 of file cmp.h. 00514 {
00515 return NAME;
00516 }
|
|
Get Cmp parameter information in a dictionary. Each parameter has one record in the dictionary. Each record contains its name, data-type, and description.
Implements EMAN::Cmp. Definition at line 528 of file cmp.h. References EMAN::TypeDict::put(). 00529 { 00530 TypeDict d; 00531 d.put("snrweight", EMObject::INT, "If set, the SNR of 'this' will be used to weight the result. If 'this' lacks CTF info, it will check 'with'. (default=0)"); 00532 d.put("ampweight", EMObject::INT, "If set, the amplitude of 'this' will be used to weight the result (default=0)"); 00533 d.put("sweight", EMObject::INT, "If set, weight the (1-D) average by the number of pixels in each ring (default=1)"); 00534 d.put("nweight", EMObject::INT, "Downweight similarity based on number of particles in reference (default=0)"); 00535 d.put("zeromask", EMObject::INT, "Treat regions in either image that are zero as a mask"); 00536 d.put("minres", EMObject::FLOAT, "Lowest resolution to use in comparison (soft cutoff). Requires accurate A/pix in image. <0 disables. Default=500"); 00537 d.put("maxres", EMObject::FLOAT, "Highest resolution to use in comparison (soft cutoff). Requires accurate A/pix in image. <0 disables. Default=10"); 00538 return d; 00539 }
|
|
Definition at line 523 of file cmp.h. 00524 { 00525 return new FRCCmp(); 00526 }
|
|
|