#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 463 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 1066 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::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. 01067 { 01068 ENTERFUNC; 01069 validate_input_args(image, with); 01070 01071 int snrweight = params.set_default("snrweight", 0); 01072 int ampweight = params.set_default("ampweight", 0); 01073 int sweight = params.set_default("sweight", 1); 01074 int nweight = params.set_default("nweight", 0); 01075 int zeromask = params.set_default("zeromask",0); 01076 float minres = params.set_default("minres",500.0f); 01077 float maxres = params.set_default("maxres",10.0f); 01078 01079 if (zeromask) { 01080 image=image->copy(); 01081 with=with->copy(); 01082 01083 int sz=image->get_xsize()*image->get_ysize()*image->get_zsize(); 01084 float *d1=image->get_data(); 01085 float *d2=with->get_data(); 01086 01087 for (int i=0; i<sz; i++) { 01088 if (d1[i]==0.0 || d2[i]==0.0) { d1[i]=0.0; d2[i]=0.0; } 01089 } 01090 01091 image->update(); 01092 with->update(); 01093 image->do_fft_inplace(); 01094 with->do_fft_inplace(); 01095 image->set_attr("free_me",1); 01096 with->set_attr("free_me",1); 01097 } 01098 01099 01100 if (!image->is_complex()) { 01101 image=image->do_fft(); 01102 image->set_attr("free_me",1); 01103 } 01104 if (!with->is_complex()) { 01105 with=with->do_fft(); 01106 with->set_attr("free_me",1); 01107 } 01108 01109 static vector < float >default_snr; 01110 01111 // if (image->get_zsize() > 1) { 01112 // throw ImageDimensionException("2D only"); 01113 // } 01114 01115 // int nx = image->get_xsize(); 01116 int ny = image->get_ysize(); 01117 int ny2=ny/2+1; 01118 01119 vector < float >fsc; 01120 01121 01122 01123 fsc = image->calc_fourier_shell_correlation(with,1); 01124 01125 // The fast hypot here was supposed to speed things up. Little effect 01126 // if (image->get_zsize()>1) fsc = image->calc_fourier_shell_correlation(with,1); 01127 // else { 01128 // double *sxy = (double *)malloc(ny2*sizeof(double)*4); 01129 // double *sxx = sxy+ny2; 01130 // double *syy = sxy+2*ny2; 01131 // double *norm= sxy+3*ny2; 01132 // 01133 // float *df1=image->get_data(); 01134 // float *df2=with->get_data(); 01135 // int nx2=image->get_xsize(); 01136 // 01137 // for (int y=-ny/2; y<ny/2; y++) { 01138 // for (int x=0; x<nx2/2; x++) { 01139 // if (x==0 && y<0) continue; // skip Friedel pair 01140 // short r=Util::hypot_fast_int(x,y); 01141 // if (r>ny2-1) continue; 01142 // int l=x*2+(y<0?ny+y:y)*nx2; 01143 // sxy[r]+=df1[l]*df2[l]+df1[l+1]*df2[l+1]; 01144 // sxx[r]+=df1[l]*df1[l]; 01145 // syy[r]+=df2[l]*df2[l]; 01146 // norm[r]+=1.0; 01147 // } 01148 // } 01149 // fsc.resize(ny2*3); 01150 // for (int r=0; r<ny2; r++) { 01151 // fsc[r]=r*0.5/ny2; 01152 // fsc[ny2+r]=sxy[r]/(sqrt(sxx[r])*sqrt(syy[r])); 01153 // fsc[ny2*2+r]=norm[r]; 01154 // } 01155 // free(sxy); 01156 // } 01157 01158 vector<float> snr; 01159 if (snrweight) { 01160 Ctf *ctf = NULL; 01161 if (!image->has_attr("ctf")) { 01162 if (!with->has_attr("ctf")) throw InvalidCallException("SNR weight with no CTF parameters"); 01163 ctf=with->get_attr("ctf"); 01164 } 01165 else ctf=image->get_attr("ctf"); 01166 01167 float ds=1.0f/(ctf->apix*ny); 01168 snr=ctf->compute_1d(ny,ds,Ctf::CTF_SNR); 01169 if(ctf) {delete ctf; ctf=0;} 01170 } 01171 01172 vector<float> amp; 01173 if (ampweight) amp=image->calc_radial_dist(ny/2,0,1,0); 01174 01175 // Min/max modifications to weighting 01176 float pmin,pmax; 01177 if (minres>0) pmin=((float)image->get_attr("apix_x")*image->get_ysize())/minres; //cutoff in pixels, assume square 01178 else pmin=0; 01179 if (maxres>0) pmax=((float)image->get_attr("apix_x")*image->get_ysize())/maxres; 01180 else pmax=0; 01181 01182 double sum=0.0, norm=0.0; 01183 01184 for (int i=0; i<ny/2; i++) { 01185 double weight=1.0; 01186 if (sweight) weight*=fsc[(ny2)*2+i]; 01187 if (ampweight) weight*=amp[i]; 01188 if (snrweight) weight*=snr[i]; 01189 if (pmin>0) weight*=(tanh(5.0*(i-pmin)/pmin)+1.0)/2.0; 01190 if (pmax>0) weight*=(1.0-tanh(i-pmax))/2.0; 01191 01192 sum+=weight*fsc[ny2+i]; 01193 norm+=weight; 01194 // printf("%d\t%f\t%f\n",i,weight,fsc[ny/2+1+i]); 01195 } 01196 01197 // This performs a weighting that tries to normalize FRC by correcting from the number of particles represented by the average 01198 sum/=norm; 01199 if (nweight && with->get_attr_default("ptcl_repr",0) && sum>=0 && sum<1.0) { 01200 sum=sum/(1.0-sum); // convert to SNR 01201 sum/=(float)with->get_attr_default("ptcl_repr",0); // divide by ptcl represented 01202 sum=sum/(1.0+sum); // convert back to correlation 01203 } 01204 01205 if (image->has_attr("free_me")) delete image; 01206 if (with->has_attr("free_me")) delete with; 01207 01208 EXITFUNC; 01209 01210 01211 //.Note the negative! This is because EMAN2 follows the convention that 01212 // smaller return values from comparitors indicate higher similarity - 01213 // this enables comparitors to be used in a generic fashion. 01214 return (float)-sum; 01215 }
|
|
Implements EMAN::Cmp. Definition at line 473 of file cmp.h. 00474 { 00475 return "Computes the mean Fourier Ring Correlation between the image and reference (with optional weighting factors)."; 00476 }
|
|
Get the Cmp's name. Each Cmp is identified by a unique name.
Implements EMAN::Cmp. Definition at line 468 of file cmp.h. 00469 {
00470 return NAME;
00471 }
|
|
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 483 of file cmp.h. References EMAN::TypeDict::put(). 00484 { 00485 TypeDict d; 00486 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)"); 00487 d.put("ampweight", EMObject::INT, "If set, the amplitude of 'this' will be used to weight the result (default=0)"); 00488 d.put("sweight", EMObject::INT, "If set, weight the (1-D) average by the number of pixels in each ring (default=1)"); 00489 d.put("nweight", EMObject::INT, "Downweight similarity based on number of particles in reference (default=0)"); 00490 d.put("zeromask", EMObject::INT, "Treat regions in either image that are zero as a mask"); 00491 d.put("minres", EMObject::FLOAT, "Lowest resolution to use in comparison (soft cutoff). Requires accurate A/pix in image. <0 disables. Default=500"); 00492 d.put("maxres", EMObject::FLOAT, "Highest resolution to use in comparison (soft cutoff). Requires accurate A/pix in image. <0 disables. Default=10"); 00493 return d; 00494 }
|
|
Definition at line 478 of file cmp.h. 00479 { 00480 return new FRCCmp(); 00481 }
|
|
|